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>
This commit is contained in:
parent
c0251f3041
commit
05cd06cff3
@ -54,7 +54,7 @@
|
|||||||
#define sleep(X) Sleep(X)
|
#define sleep(X) Sleep(X)
|
||||||
#endif
|
#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.
|
//needs to sleep more than 1 usec.
|
||||||
#ifdef Q_OS_SOLARIS
|
#ifdef Q_OS_SOLARIS
|
||||||
# define RWTESTSLEEP usleep(10);
|
# define RWTESTSLEEP usleep(10);
|
||||||
@ -416,7 +416,7 @@ void tst_QReadWriteLock::tryWriteLock()
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool threadDone;
|
bool threadDone;
|
||||||
volatile bool release;
|
QAtomicInt release;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
write-lock
|
write-lock
|
||||||
@ -466,7 +466,7 @@ public:
|
|||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
testRwlock.lockForWrite();
|
testRwlock.lockForWrite();
|
||||||
while(release==false) {
|
while(release.load()==false) {
|
||||||
RWTESTSLEEP
|
RWTESTSLEEP
|
||||||
}
|
}
|
||||||
testRwlock.unlock();
|
testRwlock.unlock();
|
||||||
@ -486,7 +486,7 @@ public:
|
|||||||
void run()
|
void run()
|
||||||
{
|
{
|
||||||
testRwlock.lockForRead();
|
testRwlock.lockForRead();
|
||||||
while(release==false) {
|
while(release.load()==false) {
|
||||||
RWTESTSLEEP
|
RWTESTSLEEP
|
||||||
}
|
}
|
||||||
testRwlock.unlock();
|
testRwlock.unlock();
|
||||||
@ -685,7 +685,7 @@ void tst_QReadWriteLock::multipleReadersBlockRelease()
|
|||||||
{
|
{
|
||||||
|
|
||||||
QReadWriteLock testLock;
|
QReadWriteLock testLock;
|
||||||
release=false;
|
release.store(false);
|
||||||
threadDone=false;
|
threadDone=false;
|
||||||
ReadLockReleasableThread rlt1(testLock);
|
ReadLockReleasableThread rlt1(testLock);
|
||||||
ReadLockReleasableThread rlt2(testLock);
|
ReadLockReleasableThread rlt2(testLock);
|
||||||
@ -695,7 +695,7 @@ void tst_QReadWriteLock::multipleReadersBlockRelease()
|
|||||||
WriteLockThread wlt(testLock);
|
WriteLockThread wlt(testLock);
|
||||||
wlt.start();
|
wlt.start();
|
||||||
sleep(1);
|
sleep(1);
|
||||||
release=true;
|
release.store(true);
|
||||||
wlt.wait();
|
wlt.wait();
|
||||||
rlt1.wait();
|
rlt1.wait();
|
||||||
rlt2.wait();
|
rlt2.wait();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user