|
From: David F. <fa...@kd...> - 2014-06-08 17:09:25
|
Hello,
I'm using helgrind quite a lot these days, and I love it.
However I wonder if it doesn't give me false positives for the case of reading
a value from a static object, which was set in the constructor.
Given that gcc does indeed implement "threadsafe statics" as per C++11 (but
even before C++11 came out), one can assume that gcc does "something like" a
mutex around the creation of the object, and therefore that there is a
"happens before" relation between the end of the constructor and the use of
this object later on, right?
In that case it would seem that helgrind needs to learn that, to avoid many
false positives.
Testcase attached.
The assembly code says
call __cxa_guard_acquire
testl %eax, %eax
je .L3
.loc 1 16 0 discriminator 2
movl $_ZZ11threadStartPvE9singleton, %edi
call _ZN9SingletonC1Ev
movl $_ZGVZ11threadStartPvE9singleton, %edi
call __cxa_guard_release
.L3:
IIRC __cxa_guard_acquire/release is the protection around the static, but I'm
not sure exactly what this means. Is there an actual happens-before relation
here?
helgrind log:
==31469== Possible data race during read of size 4 at 0x602068 by thread #3
==31469== Locks held: none
==31469== at 0x400ADF: threadStart(void*) (testcase_local_static.cpp:17)
==31469== by 0x4C2D151: mythread_wrapper (hg_intercepts.c:233)
==31469== by 0x4E3C0DA: start_thread (pthread_create.c:309)
==31469== by 0x595B90C: clone (clone.S:111)
==31469==
==31469== This conflicts with a previous write of size 4 by thread #2
==31469== Locks held: none
==31469== at 0x400BC6: Singleton::Singleton() (testcase_local_static.cpp:9)
==31469== by 0x400AD4: threadStart(void*) (testcase_local_static.cpp:16)
==31469== by 0x4C2D151: mythread_wrapper (hg_intercepts.c:233)
==31469== by 0x4E3C0DA: start_thread (pthread_create.c:309)
==31469== by 0x595B90C: clone (clone.S:111)
--
David Faure, fa...@kd..., http://www.davidfaure.fr
Working on KDE Frameworks 5
|