Boost logo

Boost :

Subject: Re: [boost] Is there interest in an alternative to the Singleton anti-pattern?
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2011-06-26 05:27:59


I would like to see the updated source code. Even if boost vault is
deprecated and moved to github, it is still a good place to post
files.

Two more remarks:
1) it would be great to use auto_ptr for instance_ptr_type. It will
make sure that the resource is deleted and the constructor called.

2)
2011/6/25 Ben Robinson <icaretaker_at_[hidden]>:
> Singularity, I feel I still must make "instance_ptr" volatile for thread
> safety.  If I do not, the compiler can store the pointer in a register, and
> other threads of execution will not see changes to its value.  The linked
> article seems mostly concerned with fencing access to the variable, which I
> am achieving by using a mutex object.  I only need volatile to
> prevent effectively reading a "cached" value for the pointer.  I found the
> following article by Andrei Alexandrescu especially interesting:
> http://drdobbs.com/cpp/184403766

It is not thread safe. Consider the article
http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf by Scott
Meyers and Andrei Alexandrescu. In the article by Andrei Alexandrescu
at http://drdobbs.com/cpp/184403766 there is no construction of object
in LockingPtr, and that makes a big difference!

Best regards,
Antony Polukhin


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