From: Darin Adler (darin_at_[hidden])
Date: 2002-02-10 22:44:43
On 2/10/02 4:26 PM, "Wyss, Felix" <felixw_at_[hidden]> wrote:
>> Yes, you are right. Keeping a weak_ptr in thread A while all shared_ptr
>> owners are in thread B is asking for trouble. This is an inherent property
>> of weak_ptr (and any non-owning pointer in general, starting with raw
>> pointers) and cannot be fixed.
> This can be fixed by providing a way to obtain a strong pointer from the weak
> pointer. Instead of the get() method, I suggest providing a strong() method
> which returns a shared_ptr.
Or maybe even an implicit conversion from weak_ptr to shared_ptr.
Unfortunately, making a thread-safe implementation of this conversion
operation is non-trivial, more complex than the thread safety that's already
in shared_ptr. Peter Dimov can explain why; maybe we can get him to explain
in this thread.
> To make operator->() thread safe, it also must return a shared_ptr instead
> of T*.
This might make some uses of operator-> thread safe, but it won't help with
operator*. A possibly better approach would be to eliminate these operations
on weak_ptr and require conversion to shared_ptr.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk