From: Andrey Semashev (andysem_at_[hidden])
Date: 2007-02-05 15:30:40
Monday, February 5, 2007, 11:17:32 PM, you wrote:
> Fabien Niñoles wrote:
>> 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;
> In a multithreaded app this might work on some platforms, on others it
> Quote from http://msdn2.microsoft.com/en-us/library/s1sb61xd.aspx:
> "Assigning to a static local variable is not thread safe and is not
> recommended as a programming practice."
> Although this isn't very concise wording (IIRC, the standard says that
> it should work for literals assigned to PODs) it seems clear that it
> won't work for non-PODs...
I guess the only way to safely initialize a static local variable is
through some call_once concept implementation. The problem in my case
is that I'd like the library to be as light as possible and as fast as
possible, so I can't make use of Boost.Thread for now.
-- Best regards, Andrey mailto:andysem_at_[hidden]