diff options
Diffstat (limited to 'cpp/test/IceUtil/thread/AliveTest.cpp')
-rw-r--r-- | cpp/test/IceUtil/thread/AliveTest.cpp | 61 |
1 files changed, 45 insertions, 16 deletions
diff --git a/cpp/test/IceUtil/thread/AliveTest.cpp b/cpp/test/IceUtil/thread/AliveTest.cpp index d1b8e3ea48a..63c4db28100 100644 --- a/cpp/test/IceUtil/thread/AliveTest.cpp +++ b/cpp/test/IceUtil/thread/AliveTest.cpp @@ -15,7 +15,6 @@ #include <IceUtil/IceUtil.h> #include <stdio.h> -#include <unistd.h> #include <AliveTest.h> #include <TestCommon.h> @@ -23,21 +22,48 @@ using namespace std; using namespace IceUtil; -static const string createTestName("thread alive"); +static const string createTestName("thread alive");
+
+class Synchronizer : public IceUtil::Monitor<IceUtil::Mutex>
+{
+public:
+ Synchronizer() : _done(false)
+ {
+ }
+
+ void p()
+ {
+ IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
+ while (!_done)
+ {
+ wait();
+ }
+ }
+
+ void v()
+ {
+ IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
+ _done = true;
+ notify();
+ }
+
+private:
+ bool _done;
+}; class AliveTestThread : public Thread { -public: - - AliveTestThread(IceUtil::RWRecMutex& m) : _m(m) - { - } +public:
+ AliveTestThread(Synchronizer& child, Synchronizer& parent) : _child(child), _parent(parent)
+ {
+ }
virtual void run() { try - { - IceUtil::RWRecMutex::TryWLock lock(_m, IceUtil::Time::seconds(1)); + {
+ _child.v();
+ _parent.p(); } catch(IceUtil::ThreadLockedException &) { @@ -45,7 +71,8 @@ public: } private: - RWRecMutex& _m; + Synchronizer& _child;
+ Synchronizer& _parent; }; typedef Handle<AliveTestThread> AliveTestThreadPtr; @@ -61,12 +88,14 @@ AliveTest::run() // // Check that calling isAlive() returns the correct result for alive and // and dead threads. - // - IceUtil::RWRecMutex m; - m.writelock(); - AliveTestThreadPtr t = new AliveTestThread(m); - IceUtil::ThreadControl c = t->start(); - test(c.isAlive()); + //
+ Synchronizer parentReady;
+ Synchronizer childReady; + AliveTestThreadPtr t = new AliveTestThread(childReady, parentReady); + IceUtil::ThreadControl c = t->start();
+ childReady.p();
+ test(c.isAlive());
+ parentReady.v(); c.join(); test(!c.isAlive()); } |