Boost logo

Boost :

From: Fabien Niñoles (fabien.ninoles_at_[hidden])
Date: 2007-02-05 14:47:37


Probably you should put it has a static local variable inside a protected
function, like this:

    //! The method returns a reference to the only dispatcher instance

    static state_dispatcher const& get()
    {
      static state_dispatcher instance;
      return instance;
    }

The only problem here is I'm not sure how the compilers reacted when
instanciating static variable inside template functions...

Fabien

2007/2/5, Andrey Semashev <andysem_at_[hidden]>:
>
> 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]
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
>


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