Yes,
But then, the question is: Can I have simultaneous read/write operations on
shared_ptr ? I don´t think so, because the reasons already exposed. Right ?
Eduardo Panisset.
On Fri, Aug 15, 2008 at 8:49 PM, David Abrahams
on Fri Aug 15 2008, "Eduardo Panisset"
http://eduardo.panisset-at-gmail.com/> wrote: Hi,
I have studied the sp_counted_base implementation and I can't see how it is trade safe.
<snip>
1. Reference count = 1 2. Thread A executes release and is interrupted after execute the comparation if( new_use_count) == 0 (the comparation returns true) 3. Thread B executes add_ref_lock, then Ref count = 1 4. Thread A executes "dispose()" and releases the pointer !
What Do you think about ?
The premise is that if reference count = 1, only one thread can possibly be referencing this shared_count. Note that shared_ptr is only supposed to be "as threadsafe as int;" it doesn't claim that a single shared_ptr object can ever be inspected or modified while it is being modified in another thread.
Yes, it's possible to be less threadsafe than int when there's hidden sharing! In that case, two threads wouldn't be able to concurrently modify/inspect *copies* of the same object (in this case, the shared_ptr).
HTH,
-- Dave Abrahams BoostPro Computing http://www.boostpro.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users