summaryrefslogtreecommitdiff
path: root/cpp/test/IceUtil/thread/AliveTest.cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2003-03-10 02:54:08 +0000
committerMichi Henning <michi@zeroc.com>2003-03-10 02:54:08 +0000
commit4be510ae7ab1c5a8542e73f06a4f5d5ccca8efd3 (patch)
treec10f8c70a540b70c5a3c3b1d45cd5e70b95e6c48 /cpp/test/IceUtil/thread/AliveTest.cpp
parentAdded IceUtil::ThreadControl::isAlive() member function. (diff)
downloadice-4be510ae7ab1c5a8542e73f06a4f5d5ccca8efd3.tar.bz2
ice-4be510ae7ab1c5a8542e73f06a4f5d5ccca8efd3.tar.xz
ice-4be510ae7ab1c5a8542e73f06a4f5d5ccca8efd3.zip
Add ThreadControl::isAlive() functionality for Windows.
Diffstat (limited to 'cpp/test/IceUtil/thread/AliveTest.cpp')
-rw-r--r--cpp/test/IceUtil/thread/AliveTest.cpp61
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());
}