summaryrefslogtreecommitdiff
path: root/cpp/test/IceUtil/thread/AliveTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/test/IceUtil/thread/AliveTest.cpp')
-rw-r--r--cpp/test/IceUtil/thread/AliveTest.cpp89
1 files changed, 45 insertions, 44 deletions
diff --git a/cpp/test/IceUtil/thread/AliveTest.cpp b/cpp/test/IceUtil/thread/AliveTest.cpp
index 63c4db28100..351a07943de 100644
--- a/cpp/test/IceUtil/thread/AliveTest.cpp
+++ b/cpp/test/IceUtil/thread/AliveTest.cpp
@@ -22,48 +22,49 @@
using namespace std;
using namespace IceUtil;
-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;
+static const string createTestName("thread alive");
+
+class CondVar : public IceUtil::Monitor<IceUtil::Mutex>
+{
+public:
+ CondVar() : _done(false)
+ {
+ }
+
+ void wait()
+ {
+ IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
+ while (!_done)
+ {
+ this->IceUtil::Monitor<IceUtil::Mutex>::wait();
+ }
+ }
+
+ void signal()
+ {
+ IceUtil::Monitor<IceUtil::Mutex>::Lock lock(*this);
+ _done = true;
+ notify();
+ }
+
+private:
+ bool _done;
};
class AliveTestThread : public Thread
{
-public:
- AliveTestThread(Synchronizer& child, Synchronizer& parent) : _child(child), _parent(parent)
- {
- }
+public:
+ AliveTestThread(CondVar& childCreated, CondVar& parentReady) :
+ _childCreated(childCreated), _parentReady(parentReady)
+ {
+ }
virtual void run()
{
try
- {
- _child.v();
- _parent.p();
+ {
+ _childCreated.signal();
+ _parentReady.wait();
}
catch(IceUtil::ThreadLockedException &)
{
@@ -71,8 +72,8 @@ public:
}
private:
- Synchronizer& _child;
- Synchronizer& _parent;
+ CondVar& _childCreated;
+ CondVar& _parentReady;
};
typedef Handle<AliveTestThread> AliveTestThreadPtr;
@@ -88,14 +89,14 @@ AliveTest::run()
//
// Check that calling isAlive() returns the correct result for alive and
// and dead threads.
- //
- Synchronizer parentReady;
- Synchronizer childReady;
- AliveTestThreadPtr t = new AliveTestThread(childReady, parentReady);
- IceUtil::ThreadControl c = t->start();
- childReady.p();
- test(c.isAlive());
- parentReady.v();
+ //
+ CondVar childCreated;
+ CondVar parentReady;
+ AliveTestThreadPtr t = new AliveTestThread(childCreated, parentReady);
+ IceUtil::ThreadControl c = t->start();
+ childCreated.wait();
+ test(c.isAlive());
+ parentReady.signal();
c.join();
test(!c.isAlive());
}