summaryrefslogtreecommitdiff
path: root/cppe/test/IceE/thread/AliveTest.cpp
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2005-07-05 11:09:55 +0000
committerDwayne Boone <dwayne@zeroc.com>2005-07-05 11:09:55 +0000
commit9b8cc712d4a41d71840416776bc94ee8485bb9b3 (patch)
tree7d467fdd6a66bc2b5878d82070d45adbd5c20414 /cppe/test/IceE/thread/AliveTest.cpp
parentcleaning the cache method out of ReferenceFactory (diff)
downloadice-9b8cc712d4a41d71840416776bc94ee8485bb9b3.tar.bz2
ice-9b8cc712d4a41d71840416776bc94ee8485bb9b3.tar.xz
ice-9b8cc712d4a41d71840416776bc94ee8485bb9b3.zip
Changed Ice to IceE EVERYWHERE!!!
Diffstat (limited to 'cppe/test/IceE/thread/AliveTest.cpp')
-rw-r--r--cppe/test/IceE/thread/AliveTest.cpp99
1 files changed, 99 insertions, 0 deletions
diff --git a/cppe/test/IceE/thread/AliveTest.cpp b/cppe/test/IceE/thread/AliveTest.cpp
new file mode 100644
index 00000000000..b6ef24a42af
--- /dev/null
+++ b/cppe/test/IceE/thread/AliveTest.cpp
@@ -0,0 +1,99 @@
+// **********************************************************************
+//
+// Copyright (c) 2003-2005 ZeroC, Inc. All rights reserved.
+//
+// This copy of Ice is licensed to you under the terms described in the
+// ICE_LICENSE file included in this distribution.
+//
+// **********************************************************************
+
+#include <IceE/IceE.h>
+#include <AliveTest.h>
+#include <TestCommon.h>
+
+using namespace std;
+using namespace IceE;
+
+static const string createTestName("thread alive");
+
+class CondVar : public IceE::Monitor<IceE::RecMutex>
+{
+public:
+
+ CondVar() :
+ _done(false)
+ {
+ }
+
+ void waitForSignal()
+ {
+ IceE::Monitor<IceE::RecMutex>::Lock lock(*this);
+ while(!_done)
+ {
+ wait();
+ }
+ }
+
+ void signal()
+ {
+ IceE::Monitor<IceE::RecMutex>::Lock lock(*this);
+ _done = true;
+ notify();
+ }
+
+private:
+
+ bool _done;
+};
+
+class AliveTestThread : public Thread
+{
+public:
+
+ AliveTestThread(CondVar& childCreated, CondVar& parentReady) :
+ _childCreated(childCreated), _parentReady(parentReady)
+ {
+ }
+
+ virtual void run()
+ {
+ try
+ {
+ _childCreated.signal();
+ _parentReady.waitForSignal();
+ }
+ catch(IceE::ThreadLockedException &)
+ {
+ }
+ }
+
+private:
+
+ CondVar& _childCreated;
+ CondVar& _parentReady;
+};
+
+typedef Handle<AliveTestThread> AliveTestThreadPtr;
+
+AliveTest::AliveTest() :
+ TestBase(createTestName)
+{
+}
+
+void
+AliveTest::run()
+{
+ //
+ // Check that calling isAlive() returns the correct result for alive and
+ // and dead threads.
+ //
+ CondVar childCreated;
+ CondVar parentReady;
+ AliveTestThreadPtr t = new AliveTestThread(childCreated, parentReady);
+ IceE::ThreadControl c = t->start();
+ childCreated.waitForSignal();
+ test(c.isAlive());
+ parentReady.signal();
+ c.join();
+ test(!c.isAlive());
+}