
Gennadiy Rozental wrote:
"Tobias Schwinger" <tschwinger@isonews2.com> wrote in message news:fmkefr$cf3$1@ger.gmane.org...
For instance, the design could be made more flexible by allowing thread-safety to be specified as a policy (with appropriate default) or by delegating the responsibility to the wrapped type. OK, FWIW policies complicate things. And what's their benefit here?
I disagree. In general policies promote modularization. In this concrete case policy based solution would allow more flexibility in how "thread-safe" I want to be.
They often also promote over-complication: Thread-safety that is more complex than applying a simple mutex is very case-dependent and should be implemented manually.
If BOOST_HAS_THREADS is defined, it looks as though I have no choice but to use mutexed instantiation and/or access. If I'm not interested in synchronised access, then the lease interface is useless. Wrong:
The lease interface is useful to improves performance. The test whether the Singleton has been initialized (which requires synchronization) can be performed only once.
The lease interface only improves preformance in your design. With Meyer's singleton instance() is as efficient. With any other solution that returns T&, I just need to store local referene to the target type.
Storing the instance is out of the question with automatic locking. [... tons of text] http://learn.to/quote Regards, Tobias