summaryrefslogtreecommitdiffstats
path: root/tests/auto/qmutex
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2011-02-03 11:47:16 +0100
committerOlivier Goffart <olivier.goffart@nokia.com>2011-02-03 11:47:16 +0100
commitfda461ddb2ae740b50544d1fd8309d51418912db (patch)
treed58cd7af2f74a3cef032b81668baef3ef06c75ec /tests/auto/qmutex
parent6e18291266ed33c27c35f069f6915c353d96ee8c (diff)
parent4de2ce7717ba52d3056f10e0a9fbb44eba4091bc (diff)
Merge remote-tracking branch 'origin/4.7' into qt-master-from-4.7
Conflicts: src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp src/opengl/gl2paintengineex/qtextureglyphcache_gl.cpp src/opengl/gl2paintengineex/qtextureglyphcache_gl_p.h
Diffstat (limited to 'tests/auto/qmutex')
-rw-r--r--tests/auto/qmutex/tst_qmutex.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/qmutex/tst_qmutex.cpp b/tests/auto/qmutex/tst_qmutex.cpp
index 3c4c7674de..ea983cbd10 100644
--- a/tests/auto/qmutex/tst_qmutex.cpp
+++ b/tests/auto/qmutex/tst_qmutex.cpp
@@ -67,6 +67,7 @@ private slots:
void lock_unlock_locked_tryLock();
void stressTest();
void tryLockRace();
+ void qtbug16115_trylock();
};
static const int iterations = 100;
@@ -464,5 +465,42 @@ void tst_QMutex::tryLockRace()
TryLockRaceThread::mutex.unlock();
}
+static volatile int qtbug16115_trylock_counter;
+
+void tst_QMutex::qtbug16115_trylock()
+{
+ //Used to deadlock on unix
+ struct TrylockThread : QThread {
+ TrylockThread(QMutex &mut) : mut(mut) {}
+ QMutex &mut;
+ void run() {
+ for (int i = 0; i < 1000000; ++i) {
+ if (mut.tryLock(0)) {
+ Q_ASSERT((++qtbug16115_trylock_counter) == 1);
+ Q_ASSERT((--qtbug16115_trylock_counter) == 0);
+ mut.unlock();
+ }
+ }
+ }
+ };
+ QMutex mut;
+ TrylockThread t1(mut);
+ TrylockThread t2(mut);
+ TrylockThread t3(mut);
+ t1.start();
+ t2.start();
+ t3.start();
+
+ for (int i = 0; i < 1000000; ++i) {
+ mut.lock();
+ Q_ASSERT((++qtbug16115_trylock_counter) == 1);
+ Q_ASSERT((--qtbug16115_trylock_counter) == 0);
+ mut.unlock();
+ }
+ t1.wait();
+ t2.wait();
+ t3.wait();
+}
+
QTEST_MAIN(tst_QMutex)
#include "tst_qmutex.moc"