Boost logo

Boost :

From: Andrey Semashev (andysem_at_[hidden])
Date: 2007-02-05 14:25:59


Hello Steven,

Monday, February 5, 2007, 9:53:35 PM, you wrote:

> AMDG

> Andrey Semashev <andysem <at> mail.ru> writes:

>>
>> Yes, you're right here. But there's nothing really dangerous in
>> running state_dispatcher constructor more than once concurrently. I'll
>> see what I can do about it, just to be on the safe side.
>>

> This has exactly the same problem that
> m_StatesInfo had. It can be used before
> it is initialized.

Yes, again you're right. I'm just not very experienced in
multithreaded programming.

I made the dispatcher instance a static class data member so it should
be initialized even before any FSM get created (I've attached the
modified file). But thinking of it some more I'm not quite sure even
this would make me absolutely safe.

The Standard says (3.6.2/3) that non-local objects with static
storage duration (which the dispatcher and, BTW, state names are) are
dynamically initialized before any function or object usage in the
translation unit where the objects are defined. Doesn't that mean that
there's a possibility that one day more than one thread may
concurrently execute this initialization by accessing a function or
object in the TU? If so, then I can hardly imagine the absolutely safe
way to protect the initialization of such global objects. I wouldn't
even be able to safely create a mutex fearing that it would be
simultaneously initialized by several threads. Is there any way to
solve this?

-- 
Best regards,
 Andrey                            mailto:andysem_at_[hidden]



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