Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2008-08-15 19:49:31


on Fri Aug 15 2008, "Eduardo Panisset" <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 list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net