Boost logo

Boost :

From: williamkempf_at_[hidden]
Date: 2001-09-17 10:54:50

--- In boost_at_y..., Jens Maurer <Jens.Maurer_at_g...> wrote:
> I think this patch (nearly) does what you want. It uses a similar
> trick than the Windows variant, but doesn't spread the mutex

After looking closer at the proposed patch this simply won't work.
The Win32 implementation uses the DCL pattern, which for IA32
implementations is safe, so I'm not as concerned there. But for
POSIX this implementation is going to run on architectures that use
aggressive reordering and the DCL simply isn't thread safe in that
case. To make it thread safe would require memory barriers, which
are non-portable (creating a portable interface may be nice, but this
is beyond my own ability and will complicate the usability of the
library when ported to new architectures). The only portable way to
use this technique is to not use DCL but instead lock the mutex every
time. Since pthread_once() can use an implementation that properly
applies memory barriers this means there may be a significant
performance penalty for using boost::call_once() that doesn't exist
for pthread_once(). (Even worse is the fact that the patch uses a
global mutex for all calls, which would add significantly more
overhead still, even on platforms that don't require memory barriers,
but there is a way to eliminate this problem.)

I'm still left wanting a better solution.

Bill Kempf

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