[Interest] llvm thread sanitizer and qmutex
Firl, Benjamin
benjamin.firl at wincor-nixdorf.com
Wed Mar 5 14:50:40 CET 2014
Hallo,
we make heavy use of Qt in our software and are now trying to use llvm thread sanitizer for debugging. Unfortunately the sanitizer doesn't seem to recognize QMutex as a locking mechanism.
The example below warns about a race condition because the member "data" is accessed in two threads. If you use a boost::mutex instead, the warning disappears. If "data" is a global variable, the false warning is also not shown.
What are the differences between the two mutex variants? Shouldn't both use pthread_mutex internally on a linux system? Are there any experiences in debugging Qt programs with llvm thread sanitizer?
Thanks in advance,
Benjamin
P.S.: I have also posted this question in the qt-project.org forum: http://qt-project.org/forums/viewthread/38975/
#include <QtConcurrentRun>
#include <QMutex>
#include <iostream>
#include <boost/thread/mutex.hpp>
//int data;
class TestClass
{
public:
void fun()
{
QMutexLocker autoMutex(&mutex);
//boost::mutex::scoped_lock bautoMutex(bmutex);
data = 1;
}
private:
int data;
QMutex mutex;
boost::mutex bmutex;
};
int main()
{
TestClass *tc = new TestClass;
QFuture<void> t1 = QtConcurrent::run(tc, &TestClass::fun);
QFuture<void> t2 = QtConcurrent::run(tc, &TestClass::fun);
t1.waitForFinished();
t2.waitForFinished();
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140305/a0802c87/attachment.html>
More information about the Interest
mailing list