Hi,
I have come across something which I believe is a bug in g++. I've
seen this issue both in 4.9.1 and 5.2.0, but I'm struggling to create
a small testcase. (The output of g++ -v for 5.2.0 is below.)
The issue is a deadlock that seems to be due to there being (runtime)
the equivalent of _two_ different variables __gthread_active_ptr. It
just so happens that in the libstdc++ pool allocator template, the
allocate() function, for a certain instantiation, is compiled so that
the lock() method of the __scoped_lock (in ext/concurrence.h) is
getting 'true' as the result of its call to __gthread_active_p(),
while in the unlock() method it gets 'false'. The next allocation of
the same type will of course deadlock due to not releasing the mutex
after the previous allocation.
Looking at the assembly code, in the unlock() method the code
if (__gthread_active_p())
is actually reduced to
mov $0x0,%eax
test %eax,%eax
so somehow g++ managed (erroneously) to fold this runtime-test during
compile time (at least that is my guess). In the lock() method it
looks like this: