[SmartPtr] local_weak_ptr?
How are boost::local_shared_ptr and boost::weak_ptr intended to be used together? I expected a local_weak_ptr, but it's not there so I'm wondering how you would (correctly) use local_shared_ptr and weak_ptr, or if you need local_weak_ptr and this is just still on the TODO list? Thanks, Rob Conde
On 9/12/2017 04:19, Rob Conde wrote:
How are boost::local_shared_ptr and boost::weak_ptr intended to be used together? I expected a local_weak_ptr, but it's not there so I'm wondering how you would (correctly) use local_shared_ptr and weak_ptr, or if you need local_weak_ptr and this is just still on the TODO list?
You can construct a shared_ptr from a local_shared_ptr and then construct a weak_ptr from that. Since local_shared_ptr isn't threadsafe, I *think* the intended use is to keep shared_ptr/weak_ptr in data structures that might be shared between threads, and copy to local_shared_ptr instances for purely thread-local data structures, in that order. But that's just an inference; I don't have any direct knowledge of the motivation.
Thanks Gavin, I was thinking of that...but then again I don’t see the weak_ptr aspect having anything to do with threading per-se, so it seems strange to have to “enter the threaded world” in order to use weak_ptr with local_shared_ptr. Of course, a patch would be pretty straightforward I think, but it would be useful to know the motivation of the current state of things before bothering. Rob
On Dec 10, 2017, at 5:10 PM, Gavin Lambert via Boost-users
wrote: On 9/12/2017 04:19, Rob Conde wrote: How are boost::local_shared_ptr and boost::weak_ptr intended to be used together? I expected a local_weak_ptr, but it's not there so I'm wondering how you would (correctly) use local_shared_ptr and weak_ptr, or if you need local_weak_ptr and this is just still on the TODO list?
You can construct a shared_ptr from a local_shared_ptr and then construct a weak_ptr from that.
Since local_shared_ptr isn't threadsafe, I *think* the intended use is to keep shared_ptr/weak_ptr in data structures that might be shared between threads, and copy to local_shared_ptr instances for purely thread-local data structures, in that order. But that's just an inference; I don't have any direct knowledge of the motivation.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Gavin Lambert
-
Rob Conde