Subj : Re: Boost.Threads on its way to C++0x To : comp.programming.threads From : gottlobfrege Date : Mon Apr 25 2005 02:23 pm Peter Dimov wrote: > Hello, > > It looks like Boost.Threads (or a reasonable facsimile thereof) is well on > its way to become part of the next C++ standard (C++0x): > > http://lists.boost.org/boost/2005/04/24636.php > http://lists.boost.org/boost/2005/04/24671.php > > As usual, once something gets into a standard, it can practically never be > retracted, regardless of its merits. > > So... I ask you to please take a look at Boost.Threads: > > http://boost.org/doc/html/threads.html > > and the Dinkumware implementation: > > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1682.html > > (Metrowerks also ships a threading library with CodeWarrior but I don't have > a link.) > > If you see anything broken, please comment. > > -- > Peter Dimov > http://www.pdimov.com I think their implementation of call_once leaves a lot to be desired: - not 'optimal' - ie minimizing the time of the 'init' path of execution (vs the waiting path) - not exception safe (or cancelable (in the pthreads sense) - doesn't take a functor I would prefer, and am working on, - 2 separate versions - split depending on how you want to handle exceptions (a non-exception implementation can be faster than an exception safe one) - A 'Once' object: int func() { static Once once; if (Once::Sentry sentry = once) { // do stuff once } // else wait for if block (in another thread) to finish } - a static_local template: int func() { // this thread-safely inits foo only once static static_local foo(foo_param1, foo_param2,...); // somewhat unfortunately, the resulting object // must be left with pointer syntax (can't override '.') int x = foo->bar; } Haven't much looked at the rest. pthreads guarantees that the various mutex objects can be static-initted. Like: Mutex mutex = MUTEX_INIT; Windows doesn't have that, but you can make it (either using call_once, or directly, then use your static-initted mutex to implement call_once). .