Boost logo

Boost :

Subject: Re: [boost] Review Request: Singularity
From: Kim Barrett (kab.conundrums_at_[hidden])
Date: 2011-08-23 22:40:12


On Aug 23, 2011, at 4:26 PM, Stephan T. Lavavej wrote:
> I've heard (but don't take my word for it) that GCC currently
> ensures correctness here by taking a lock, which is far less desirable
> than the novel magic statics algorithm.

On Aug 23, 2011, at 5:34 PM, Mathias Gaunard wrote:
> I'm just thinking of them being thread-safe.
> [...]
> They have been thread-safe in GCC at least since version 4.0.
> It is mandated by the Itanium C++ ABI that is followed by most compilers.

For what it's worth, only sort of.

gcc 4.0 - 4.2 used a single global mutex in the implementation of
thread-safe function scoped static variables, and held this mutex
locked while executing the initializer. This can deadlock if the
initializer for such a variable requires the result from a computation
done by another thread, and part of that computation attempts to
initialize some other function scoped static variable. [It is an error
in the program if it is the same variable that needs to be
initialized.]

In gcc 4.3 the relevant code (__cxa_guard_acquire) was changed to (1)
eliminate the use of a global lock under some configurations (have
futexes), (2) avoid holding the global lock while performing the
initialization under other configurations (have condition variables),
(3) finally, fall back to the old pre-4.3 behavior if neither of those
configurations is enabled.

Yes, I learned all about this the hard way.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk