|
Boost : |
From: Pete Becker (petebecker_at_[hidden])
Date: 2002-06-28 12:06:01
At 09:45 AM 6/28/2002 -0700, Joachim Achtzehnter wrote:
>Isn't it true that in practice, ordinary pointers are often slighly more
>thread-safe than shared_ptr because on many platforms pointer assignments
>are atomic, while shared_ptr assignments are not. Portable programs can't
>rely on pointer assignments being atomic, of course, so I'm not suggesting
>one should make use of this fact, but it might explain why people can be
>surprised by this observed difference in behaviour.
On single processor systems atomicity is the prime issue. On
multi-processor systems it's not sufficient: each processor can have its
own memory cache, and cache updates can happen out of order, so a processor
can see a new pointer value stored by some other processor (i.e. some other
thread) without seeing the new data that the pointer points to. Each thread
must unlock a mutex to make changes reliably visible to other threads, and
each thread must lock the same mutex to reliably see changes made by other
threads.
Think of a mutex as an inter-thread sequence point. That is, assuming you
understand sequence points. <g>
-- Pete
Dinkumware, Ltd.
"Genuine Software"
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk