Boost logo

Boost :

Subject: Re: [boost] Is there interest in an alternative to the Singleton anti-pattern?
From: Ben Robinson (icaretaker_at_[hidden])
Date: 2011-06-24 03:06:27


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


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