Boost logo

Boost :

From: Pavel Vozenilek (pavel_vozenilek_at_[hidden])
Date: 2005-02-13 15:31:43


"Dave Handley" wrote:

[bald pointer out of singleton]
>
> The only instance that I can think of where you may want to do this is in
> a multi-threaded environment. And even then only in a very specific set
> of circumstances. Specifically, you may want to do this when you don't
> want the overhead of a lock, but, for some other reason, you can
> absolutely guarantee that concurrent access to the object (or parts of the
> object you are accessing) is valid. If I'm honest though, I'm having some
> difficulty convincing myself that something like this would actually
> genuinely be useful. Perhaps if you could get a "bald pointer" through a
> protected member, that was therefore only accessible to derived classes
> (hence the singletons themselves). This could be useful to build into a
> static access function that provided a safe pointer, but perhaps without
> the overhead of a lock?
>
The use case is a legacy code that accepts only bald pointer.

A singleton may have function unsafe_get(). The object would be
instantiated if not already.

Code using its result will promise not to destroy given object.

/Pavel


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