summaryrefslogtreecommitdiff
path: root/cpp/test/IceUtil/thread/AliveTest.cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2003-03-10 01:27:01 +0000
committerMichi Henning <michi@zeroc.com>2003-03-10 01:27:01 +0000
commit889e1b049ebb34b57edf9ae62760fcb6e3fca95f (patch)
tree433acbcb23986b7e260c138f8239ef36dace7cf7 /cpp/test/IceUtil/thread/AliveTest.cpp
parentdyn thread pool (diff)
downloadice-889e1b049ebb34b57edf9ae62760fcb6e3fca95f.tar.bz2
ice-889e1b049ebb34b57edf9ae62760fcb6e3fca95f.tar.xz
ice-889e1b049ebb34b57edf9ae62760fcb6e3fca95f.zip
Added IceUtil::ThreadControl::isAlive() member function.
Diffstat (limited to 'cpp/test/IceUtil/thread/AliveTest.cpp')
-rw-r--r--cpp/test/IceUtil/thread/AliveTest.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/cpp/test/IceUtil/thread/AliveTest.cpp b/cpp/test/IceUtil/thread/AliveTest.cpp
new file mode 100644
index 00000000000..d1b8e3ea48a
--- /dev/null
+++ b/cpp/test/IceUtil/thread/AliveTest.cpp
@@ -0,0 +1,72 @@
+// **********************************************************************
+//
+// Copyright (c) 2003
+// ZeroC, Inc.
+// Billerica, MA, USA
+//
+// All Rights Reserved.
+//
+// Ice is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License version 2 as published by
+// the Free Software Foundation.
+//
+// **********************************************************************
+
+#include <IceUtil/IceUtil.h>
+
+#include <stdio.h>
+#include <unistd.h>
+
+#include <AliveTest.h>
+#include <TestCommon.h>
+
+using namespace std;
+using namespace IceUtil;
+
+static const string createTestName("thread alive");
+
+class AliveTestThread : public Thread
+{
+public:
+
+ AliveTestThread(IceUtil::RWRecMutex& m) : _m(m)
+ {
+ }
+
+ virtual void run()
+ {
+ try
+ {
+ IceUtil::RWRecMutex::TryWLock lock(_m, IceUtil::Time::seconds(1));
+ }
+ catch(IceUtil::ThreadLockedException &)
+ {
+ }
+ }
+
+private:
+ RWRecMutex& _m;
+};
+
+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.
+ //
+ IceUtil::RWRecMutex m;
+ m.writelock();
+ AliveTestThreadPtr t = new AliveTestThread(m);
+ IceUtil::ThreadControl c = t->start();
+ test(c.isAlive());
+ c.join();
+ test(!c.isAlive());
+}