|
Boost Users : |
Subject: [Boost-users] weak_ptr copying causes destruction
From: Travis Gockel (travis_at_[hidden])
Date: 2012-06-11 12:47:44
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
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