Boost logo

Boost :

From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2001-07-31 18:11:24

> Any way, the implementation is going to require some initialization
> code that needs to be run only once even if multiple threads access
> the data after it's initialized. 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
> and tear down stuff. There's obvious drawbacks to this approach and
> it's not portable in any event. So the question is, does
> Boost.Threads need once functions, and if so what sort of interface
> should we put on it?

how about some generic singleton template. ideally,
in thread-aware C++200x ;) it would be really great
to be able to write something like:

Singleton& Singleton::getInstance()
  static synch Singleton singleton( .... );
  return singleton;

(synchronized static locals)


ps. a) linuxthreads has a portable impl. for pthread_once
       using DCL with memory barriers macros;

    b) pthreads-win32 uses DCL w/o memory barriers;
       OK on win32 (IA32; in-order memory model);
       not so sure with respect to IA64 windows
       version (out-of-order native memory model)

    c) completely portable version could
       be implemented via DCL with ThreadLocals

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