Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-05-15 06:34:06


From: "Thomas Witt" <witt_at_[hidden]>
>
> The problem I have with this change is that it not only breaks my code but
it
> breaks my design.
>
> Up to now I have used shared <-> weak ptr to communicate ownership. Shared
ptr
> implies shared ownership whereas a weak_ptr implies non ownership by the
> entity holding the weak_ptr. Think of an object holding a
shared_ptr<smth.>
> internally and only providing access via weak_ptr. Clients can still stow
> away the weak ptr. But the usage of weak_ptr clearly communicates: "Take
care
> it might go away." and in advantage to bald pointers the client can take
care
> as he can query the weak ptr about this.
>
> Providing weak -> shared conversion completely breaks this design as
clients
> can take ownership whenever they like.

Something along these lines was my initial argument against providing
weak -> shared conversions when Darin suggested it. But: these conversions
are the only way to make a weak_ptr safe, especially in a multithreaded
environment; and they don't actually _break_ the design.

The intended use pattern is for clients to take ownership only temporary, as
if holding a lock on the object; clearly, the object shouldn't go away in
the middle of a "transaction."

Even if clients abuse the conversion, and take permanent ownership, this
doesn't break the "object server." It still operates as usual. Presumably
the client has good reasons to keep that particular object alive.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk