Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-05-03 08:22:51


From: "Christophe Meessen" <christophe_at_[hidden]>
> Suppose three threads attempting to do something on the shared_ptr.
> T1 is first and access the protected counter.
> T2 arrives just then, and is executing reset(). So it blocks on the
> mutex and waits for T1 to complete its operation.
> The T3 arrives and copies the shared_ptr to another one, so it should
> increment.

This is undefined behavior. shared_ptr is as thread safe as an int (by the
posix memory rules.) In other words, you can't write to and access a
shared_ptr at the same time. You can, however, read and write different
shared_ptr's at the same time, even if they share ownership; and you can
read (copy, for instance) a single shared_ptr from several threads.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk