Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2005-09-13 12:14:36

> I should probably elaborate on my problem a little bit more. I wanted
> to create a function that makes a given call atomic, but doesn't enforce
> that the function be called only once. I thought I could do so by using
> a once_flag allocated on the stack immediately before invoking
> call_once, so the flag would always be reinitialized to BOOST_ONCE_INIT
> and call_once could just offer me it's atomic guarantees, but apparently
> that won't work. I guess I'll just have to find some place to put my
> own mutex where it can be constructed safely.

I forgot to mention:

1) I had the same issue in Boost.Regex and wrote a statically initialised
mutex as a solution (see boost/regex/pending/static_mutex.hpp), it might
make a useful addition to the threading lib, however, I really should
rewrite the Win32 implementation to use a mutex so you don't get a priority
inversion and busy waiting (see

2) It's possible to do what you want with call_once, but it's one of those
things you might think is impossible until someone shows you how, and then
it's embarrassingly easy, see for an explanation.

HTH, John.

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