Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2008-08-16 20:32:14


on Sat Aug 16 2008, "Eduardo Panisset" <eduardo.panisset-AT-gmail.com> wrote:

> There are two threads, each one with its own shared_ptr. Thread 2 created
> its shared_ptr2 by copying the shared_prt1 of thread 1. Then the reference
> count is equal to 2.
> Some time later, shared_ptr1 goes out of scope and then shared_prt2 also
> goes out of scope.
> Consider the following event sequence:
>
> 1. Thread 1 executes release member function, and it is preempted before
> executing comparation if (new_use_count == 0)
> 2. Thread 2 executes release member function until the end, disposing the
> pointee.
> 3. Thread 1 is rescheduled, executes comparation if (new_use_count == 0) and
> also diposes the pointee!
>
> Is it possible, isn't it?

No. Thread 1 will see new_use_count == 1, thread 2 will see
new_use_count == 0 and dispose the pointee, and thread 1 will continue
off the end of the function without disposing it.

-- 
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