1 Aug 2001 09:16
Re: Boost.Threads - once functions
<tneumann <at> writeme.com>
2001-08-01 07:16:44 GMT
2001-08-01 07:16:44 GMT
> POSIX uses pthread_once to do this,
> but there's no Win32 equivalent. Instead, Win32 programmers are
> expected to make use of DllMain to handle this sort of
initialization
in Win32 pthread_once can be simulated by using something similar to
the the following:
struct OnceInfo {
DWORD counter;
bool done;
};
static OnceInfo info = {-1,false};
void doOnce(OnceInfo& info,void (*foo)())
{
if (InterlockedIncrement(&info.counter)==0) {
foo();
info.done=true;
} else while (!info.done) Sleep(0);
}
void someFunc() { doOnce(info,foo); }
RSS Feed