Boost logo

Boost :

From: Andrey Semashev (andysem_at_[hidden])
Date: 2007-02-05 16:10:23

Hello Andreas,

>> However, if
>> that's bother, I think then only something like Loki Singleton
>> pattern will do.
>> You then need a double lock for accessing it correctly, something
>> like this:
>> static state_dispatcher const& get()
>> {
>> static state_dispatcher* pInstance;
>> scoped_lock first_lock(m_mutex1)
>> if (!pInstance)
>> {
>> scoped_lock second_lock(m_mutex2);
>> if (!pInstance)
>> {
>> pInstance = new state_dispatcher;
>> }
>> }
>> return *pInstance;
>> }

> From where did you get m_mutex1 & m_mutex2?? Where are they initialized?

I guess there should have been only "scoped_lock
second_lock(m_mutex2)" and no "scoped_lock first_lock(m_mutex1)".
Still, m_mutex2 has to be initialized somewhere and I see no other way
for it than to be global, in namespace scope. But once again, I'm not
sure even this is actually safe since it's dynamic initialization
which apparently may be done concurrently.

Best regards,
 Andrey                            mailto:andysem_at_[hidden]

Boost list run by bdawes at, gregod at, cpdaniel at, john at