
11 Jun
2012
11 Jun
'12
4:47 p.m.
The copy constructor for weak_ptr constructs px like so: px(r.lock().get()) Why do it this way and not just: px(r.px) This introduces a somewhat unexpected race in that the shared_ptr obtained with lock() can be the last outstanding shared_ptr and the object can be destroyed during this copy. It is certainly not a *bug* in the smart_ptr library, but the behavior is unexpected and quite inconvenient. I assume there is a reason for calling lock() and not just copying the pointer and I would like to know what it is. Thanks, Travis Gockel Chief λ Combinator