Boost logo

Boost Users :

Subject: Re: [Boost-users] in IOS, thread_info object is being destructed before the thread finishes executing
From: Nat Linden (nat_at_[hidden])
Date: 2013-02-04 14:58:49


On Mon, Feb 4, 2013 at 7:38 AM, Andy Weinstein <andyw_at_[hidden]> wrote:

> This seems to happen as a result of the smart pointer reaching a zero count,
> even though it is obviously still
> in scope in the thread_proxy function which creates it and runs the
> requested function in the thread.

I feel obliged to mention a likely scenario in which a shared_ptr's
count can reach zero prematurely, namely when multiple shared_ptrs are
created from the same raw (native) pointer, e.g.

Object* myobj = new Object();
shared_ptr<Object> sp1(myobj);
shared_ptr<Object> sp2(myobj);

sp1's count will be 1, as will sp2's. When either shared_ptr's count
goes to zero, myobj will be destroyed, even if the other shared_ptr is
still "live."

> I should also note that when we did catch this happening the trap, we saw
> the destructor for
> ~shared_count appear twice consecutively on the stack in Xcode source. Very
> doubleweird.

Multiple shared_count instances make me suspicious of a scenario like the above.


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