Boost logo

Boost :

From: Steven Watanabe (steven_at_[hidden])
Date: 2007-02-05 16:10:17


Andrey Semashev <andysem <at>> writes:

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

I believe that volatile works just as well here
as it does for m_StatesInfo.

template<class Dispatcher>
struct static_event_dispatcher {
    static volatile bool initialized;
    //Dispatcher must have a trivial default constructor
    static Dispatcher dispatcher;
    static Dispatcher& value() {
        if(!initialized) {
            const_cast<volatile Dispatcher&>(dispatcher).init();
            initialized = true;

template<class Dispatcher>
static volatile bool static_event_dispatcher<Dispatcher>::initialized = 0;
template<class Dispatcher>
static Dispatcher static_event_dispatcher<Dispatcher>::dispatcher;

In Christ,
Steven Watanabe

Boost list run by bdawes at, gregod at, cpdaniel at, john at