Re: Fwd: memory



On Friday 19 May 2006 06:45, Ramashish Baranwal wrote:

[snip]

> shared_ptr is used to provide access to the underlying object, so you
> need not modify the "same instance of the shared_ptr" in another
> thread. Normally different threads used different instances of
> shared_ptrs all providing access to the same object. As a side note if
> you look closely even assignment of shared_ptrs modify their internals
> (reference count). But that is an implementation detail.

To make shared pointers employing reference counting thread safe in the 
pointer sense, the only thing which needs to be treated atomically 
thread-wise is the reference count.

There are some smart pointers which claim to provide low-overhead locking for 
the referenced object (see eg http://axter.com/smartptr/ and its associated 
mutex_wrapper class).  I find it difficult to believe it is true that this 
can be done generically in a way which is either efficient or avoids 
deadlocks, but from time to time you are surprised.

Chris




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]