Re: [boost] Is there interest in an alternative to the Singleton anti-pattern?

Antony, Thank you for your interest. The Singularity Pattern (as I am calling it) is policy based, and allows you to supply the threading model as a template parameter. If you choose the default policy of single_threaded, there is no thread safety, but there is also no overhead in using a mutex and using a volatile pointer. If you choose the multi_threaded policy, you get thread safety. The user of Singularity can also create a multi threaded policy of their own, implemented using the mutex of their choice, should their platform not support the boost::mutex. I am currently working as a real-time, embedded C++ developer, and therefore I often need to disable exceptions on small microcontrollers, and don't need/can't afford thread safety. That is why in addition to using a policy to control the threading model, I have implemented Singularity to use assert instead of exceptions, if BOOST_NO_EXCEPTIONS is defined. I look forward to your feedback on the Singularity Pattern. The unittests in Vault/Singularity/singularity_unittest.cpp are great to study first to see how Singularity is meant to be used. Thank you, Ben Robinson, Ph.D. My interest is piqued. Is your solution thread safe? Best regards, Antony Polukhin

On 24 June 2011 02:06, Ben Robinson <icaretaker@gmail.com> wrote:
If you choose the default policy of single_threaded, there is no thread safety, but there is also no overhead in using a mutex and using a volatile pointer.
Volatile in C++ doesn't really help with threading... Check out < http://software.intel.com/en-us/blogs/2007/11/30/volatile-almost-useless-for-multi-threaded-programming/> for one of many articles on the subject. -- Nevin ":-)" Liber <mailto:nevin@eviloverlord.com> (847) 691-1404
participants (2)
-
Ben Robinson
-
Nevin Liber