This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Seeking advice on creating reduced testcase


On 09/24/2015 03:40 PM, Johan Alfredsson wrote:
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.
For a locking or race condition issue, you might consider using hellgrind to gain an understanding of what's going wrong without having to further reduce the source. Once you have that understanding, it may be possible to show the problem with simpler source or just explain what's going wrong (if indeed it is a compiler issue).


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:
That would be an indication that the compiler thinks all the other tests were redundant. The compiler is quite aggressive at trying to track this kind of stuff.

jeff


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]