Boost logo

Boost Users :

Subject: Re: [Boost-users] Thread Safety of shared_ptr
From: Peter Dimov (pdimov_at_[hidden])
Date: 2011-05-03 08:18:37


Kevin Frey wrote:

> 2. One thread A creating another shared_ptr to the shared object,
> attempting to increment the reference count.
>
> 3. Another thread B simultaneously destroying a *different*
> shared_ptr which is connected to the same underlying shared object,
> decrementing the reference count.

This is OK. Manipulating different shared_ptr instances in different threads
is fine. The example states that you can't, in thread B, destroy the
shared_ptr which thread A copies (*sp_Session in your code). Destroying
other shared_ptr instances is allowed, regardless of whether or with what
they share ownership. The thread safety rules work on shared_ptr instances,
not on their pointees. You can replace shared_ptr with std::string (or even
int) in the examples and they will be equally valid (provided that reset is
replaced with assignment). (Although I admit that the variable names are
used somewhat loosely.)


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