diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/IceUtil/RWRecMutex.cpp | 3 | ||||
-rw-r--r-- | cpp/test/IceUtil/thread/RWRecMutexTest.cpp | 14 |
2 files changed, 12 insertions, 5 deletions
diff --git a/cpp/src/IceUtil/RWRecMutex.cpp b/cpp/src/IceUtil/RWRecMutex.cpp index 414a9e079ac..631e6a10658 100644 --- a/cpp/src/IceUtil/RWRecMutex.cpp +++ b/cpp/src/IceUtil/RWRecMutex.cpp @@ -395,7 +395,7 @@ IceUtil::RWRecMutex::timedUpgrade(const Time& timeout) const { bool result = _upgrader.timedWait(lock, remainder); --_waitingWriters; - if(result == false) + if(!result) { _upgrading = false; ++_count; @@ -416,6 +416,7 @@ IceUtil::RWRecMutex::timedUpgrade(const Time& timeout) const // The lock isn't acquired if a timeout occurred. // ++_count; + _upgrading = false; return false; } } diff --git a/cpp/test/IceUtil/thread/RWRecMutexTest.cpp b/cpp/test/IceUtil/thread/RWRecMutexTest.cpp index 738d94d7d22..5c053e539c7 100644 --- a/cpp/test/IceUtil/thread/RWRecMutexTest.cpp +++ b/cpp/test/IceUtil/thread/RWRecMutexTest.cpp @@ -280,7 +280,7 @@ public: // // Acquire a read lock. // - RWRecMutex::TryRLock tlock(_m); + RWRecMutex::RLock tlock(_m); { Lock sync(*this); @@ -828,10 +828,8 @@ RWRecMutexTest::run() mutex.readLock(); RWRecMutexUpgradeThreadPtr t1 = new RWRecMutexUpgradeThread(mutex); - RWRecMutexWriteThreadPtr t2 = new RWRecMutexWriteThread(mutex); - + ThreadControl control1 = t1->start(); - ThreadControl control2 = t2->start(); // // Its not necessary to sleep here, since the upgrade thread @@ -839,7 +837,15 @@ RWRecMutexTest::run() // write thread cannot get the write lock. // t1->waitUpgrade(); +
+ RWRecMutexWriteThreadPtr t2 = new RWRecMutexWriteThread(mutex);
+ ThreadControl control2 = t2->start();
t2->waitWrite(); + //
+ // Its necessary to sleep for 1 second to ensure that the
+ // thread is actually IN the write lock and waiting.
+ //
+ ThreadControl::sleep(Time::seconds(1));
// // Unlocking the read mutex lets the upgrade continue. At this |