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;
    }
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to