Boost logo

Boost Users :

From: Eduardo Panisset (eduardo.panisset_at_[hidden])
Date: 2008-08-16 00:21:13


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 <dave_at_[hidden]> wrote:

>
> on Fri Aug 15 2008, "Eduardo Panisset" <eduardo.panisset-AT-gmail.com<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_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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