summaryrefslogtreecommitdiffstats
path: root/tests/auto/qmutex/tst_qmutex.cpp
diff options
context:
space:
mode:
authorSergio Ahumada <sergio.ahumada@nokia.com>2011-02-08 09:27:33 (GMT)
committerSergio Ahumada <sergio.ahumada@nokia.com>2011-02-08 09:27:33 (GMT)
commit4e5c366afd6d6f8ccb3fc44cd2f6c522a3192b2d (patch)
treeae92b9ecf30e6c663e5868d97e44cae4bf712031 /tests/auto/qmutex/tst_qmutex.cpp
parentf34259ed82da481f009830839ad4d421d9b80780 (diff)
parent74baf1887d6b0965e140ae4e22799c983309eea5 (diff)
downloadQt-4e5c366afd6d6f8ccb3fc44cd2f6c522a3192b2d.zip
Qt-4e5c366afd6d6f8ccb3fc44cd2f6c522a3192b2d.tar.gz
Qt-4e5c366afd6d6f8ccb3fc44cd2f6c522a3192b2d.tar.bz2
Merge branch '4.7-review' into 4.7
Diffstat (limited to 'tests/auto/qmutex/tst_qmutex.cpp')
-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 3c4c767..ea983cb 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"