Boost logo

Boost :

From: Wyss, Felix (felixw_at_[hidden])
Date: 2002-02-10 19:26:08

> 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. To make operator->() thread safe, it also must return a shared_ptr instead of T*.


Boost list run by bdawes at, gregod at, cpdaniel at, john at