
Andrey Semashev wrote:
Hello Andreas,
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 doesn't:
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.
I guess so if you want to make it easy for the users. Another option would be to require them to call a static initialize function from main() before they start any additional threads. -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.