Boost logo

Boost :

From: Andreas Huber (ahd6974-spamgroupstrap_at_[hidden])
Date: 2007-02-05 15:17:32


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...

Regards,

-- 
Andreas Huber
When replying by private email, please remove the words spam and trap
from the address shown in the header. 

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