|
From: David F. <fa...@kd...> - 2016-03-19 21:03:10
|
The following code (from Qt5's qlogging.cpp)
static thread_local bool msgHandlerGrabbed = false;
static bool grabMessageHandler()
{
if (msgHandlerGrabbed)
return false;
msgHandlerGrabbed = true;
return true;
}
static void ungrabMessageHandler()
{
msgHandlerGrabbed = false;
}
(purpose: avoiding recursion)
when compiled with clang 3.5.0, and called from multiple threads, leads to this helgrind warning:
==1218== Possible data race during write of size 1 at 0x1E1F86F0 by thread #17
==1218== Locks held: none
==1218== at 0x783637B: grabMessageHandler() (qlogging.cpp:1543)
==1218== by 0x783640B: qt_message_print(QtMsgType, QMessageLogContext const&, QString const&) (qlogging.cpp:1571)
==1218== by 0x783658A: qt_message_output(QtMsgType, QMessageLogContext const&, QString const&) (qlogging.cpp:1622)
==1218== by 0x798DC32: QDebug::~QDebug() (qdebug.cpp:150)
==1218== by 0x4F24EF6: CompletionThread::done() (kurlcompletion.cpp:232)
==1218== by 0x4F1ECCD: DirectoryListThread::run() (kurlcompletion.cpp:368)
==1218== by 0x784B0B6: QThreadPrivate::start(void*) (qthread_unix.cpp:340)
==1218== by 0x4C3005E: mythread_wrapper (hg_intercepts.c:389)
==1218== by 0x9DAE0A3: start_thread (pthread_create.c:309)
==1218== by 0x869100C: clone (clone.S:111)
==1218==
==1218== This conflicts with a previous write of size 1 by thread #16
==1218== Locks held: none
==1218== at 0x7836399: ungrabMessageHandler() (qlogging.cpp:1549)
==1218== by 0x78364BC: qt_message_print(QtMsgType, QMessageLogContext const&, QString const&) (qlogging.cpp:1579)
==1218== by 0x783658A: qt_message_output(QtMsgType, QMessageLogContext const&, QString const&) (qlogging.cpp:1622)
==1218== by 0x798DC32: QDebug::~QDebug() (qdebug.cpp:150)
==1218== by 0x4F24EF6: CompletionThread::done() (kurlcompletion.cpp:232)
==1218== by 0x4F1ECCD: DirectoryListThread::run() (kurlcompletion.cpp:368)
==1218== by 0x784B0B6: QThreadPrivate::start(void*) (qthread_unix.cpp:340)
==1218== by 0x4C3005E: mythread_wrapper (hg_intercepts.c:389)
==1218== Address 0x1e1f86f0 is in a rw- anonymous segment
Helgrind bug, or is clang silently ignoring thread_local?
--
David Faure, fa...@kd..., http://www.davidfaure.fr
Working on KDE Frameworks 5
|