summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2013-09-21 16:11:57 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-23 02:47:49 +0200
commit05cd06cff378cecec071a2aa6f7cb4ee97a9ea6f (patch)
tree751e749191462c363a6c742e1d06f54d92cbfb76 /tests
parentc0251f3041b9c7d6968e34dcdb8dd1b24a2c97c6 (diff)
tst_QReadWriteLock: replace a volatile bool with an atomic int
Fixes the obvious race between the test of 'release' in the thread and the setting of 'release' in the test function. Change-Id: I92df52d7b18e8154f17229a3dbd4a0e58f4a3b5b Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp b/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp
index 8991d2e5b9..7d041e69cb 100644
--- a/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp
+++ b/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp
@@ -54,7 +54,7 @@
#define sleep(X) Sleep(X)
#endif
-//on solaris, threads that loop one the release bool variable
+//on solaris, threads that loop on the release bool variable
//needs to sleep more than 1 usec.
#ifdef Q_OS_SOLARIS
# define RWTESTSLEEP usleep(10);
@@ -416,7 +416,7 @@ void tst_QReadWriteLock::tryWriteLock()
}
bool threadDone;
-volatile bool release;
+QAtomicInt release;
/*
write-lock
@@ -466,7 +466,7 @@ public:
void run()
{
testRwlock.lockForWrite();
- while(release==false) {
+ while(release.load()==false) {
RWTESTSLEEP
}
testRwlock.unlock();
@@ -486,7 +486,7 @@ public:
void run()
{
testRwlock.lockForRead();
- while(release==false) {
+ while(release.load()==false) {
RWTESTSLEEP
}
testRwlock.unlock();
@@ -685,7 +685,7 @@ void tst_QReadWriteLock::multipleReadersBlockRelease()
{
QReadWriteLock testLock;
- release=false;
+ release.store(false);
threadDone=false;
ReadLockReleasableThread rlt1(testLock);
ReadLockReleasableThread rlt2(testLock);
@@ -695,7 +695,7 @@ void tst_QReadWriteLock::multipleReadersBlockRelease()
WriteLockThread wlt(testLock);
wlt.start();
sleep(1);
- release=true;
+ release.store(true);
wlt.wait();
rlt1.wait();
rlt2.wait();