
Dear all, it is already posted a dozen times, but still I do not get it. I understand that if you have a class, the shared_ptr will not make this thread safe. That's fair. Non const operations accessed by different threads should still be guarded (and probably their const versions then also). But what about the shared_ptr itself. From the doc's (http://www.boost.org/libs/smart_ptr/shared_ptr.htm#ThreadSafety) I read that reading and writing to the shared_ptr object (not the pointee) is safe: 'A shared_ptr instance can be "read" (accessed using only const operations) simultaneously by multiple threads. Different shared_ptr instances can be "written to" (accessed using mutable operations such as operator= or reset) simultaneosly by multiple threads (even when these instances are copies, and share the same reference count underneath.)' However then a couple of examples are listed where both operator= and a dtor call are marked as undefined, and this is of course the most use (share a shared pointer over multiple threads and let them decide who finishes last, but this is then illegal?)
From the code I see that the ref counting is implemented through atomic inc's and dec's, and I would therefore expect that it is thread safe after all, since only the thread which makes the ref count 0 will be assigned the job of 'dispose', and the ref counting is thread safe.
who can help this poor programmer... wkr, me