
On Mon, Feb 4, 2013 at 7:38 AM, Andy Weinstein
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.