summaryrefslogtreecommitdiff
path: root/cpp/include/IceUtil/Thread.h
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2003-03-12 04:25:17 +0000
committerMichi Henning <michi@zeroc.com>2003-03-12 04:25:17 +0000
commit5fbef4d3304ddd53c29bcb3ebd89380dbbc94d6e (patch)
treedf685d3e358750fe97507811eb1861531884b5e6 /cpp/include/IceUtil/Thread.h
parentRemoved unused definition of UnknownEndpointType. (diff)
downloadice-5fbef4d3304ddd53c29bcb3ebd89380dbbc94d6e.tar.bz2
ice-5fbef4d3304ddd53c29bcb3ebd89380dbbc94d6e.tar.xz
ice-5fbef4d3304ddd53c29bcb3ebd89380dbbc94d6e.zip
Removed _detached member from ThreadControl. Joining with a thread more
than once or detaching a detached thread or joining with a detached thread now has undefined behavior (instead of throwing an exception). Cleaned up a number of race conditions around the _id members of Thread and ThreadControl. Explicitly hid the assignment operator and copy constructor of Thread so we get better diagnostics for that.
Diffstat (limited to 'cpp/include/IceUtil/Thread.h')
-rw-r--r--cpp/include/IceUtil/Thread.h26
1 files changed, 15 insertions, 11 deletions
diff --git a/cpp/include/IceUtil/Thread.h b/cpp/include/IceUtil/Thread.h
index 73d0b7e70d9..bd411079baf 100644
--- a/cpp/include/IceUtil/Thread.h
+++ b/cpp/include/IceUtil/Thread.h
@@ -66,6 +66,9 @@ public:
ThreadControl(pthread_t);
#endif
+ ThreadControl(const ThreadControl&);
+ ThreadControl& operator=(const ThreadControl&);
+
bool operator==(const ThreadControl&) const;
bool operator!=(const ThreadControl&) const;
bool operator<(const ThreadControl&) const;
@@ -80,19 +83,19 @@ public:
// semantics.
//
// At most one thread can wait for the termination of a given
- // thread.C alling join on a thread on which another thread is
- // already waiting for termination results in undefined behaviour.
- // Joining with a thread after having joined with it previously,
- // or joining with a detached thread raises ThreadSyscallException.
+ // thread. Calling join on a thread on which another thread is
+ // already waiting for termination results in undefined behaviour,
+ // as does joining with a thread after having joined with it previously,
+ // or joining with a detached thread.
//
void join();
//
// Detach a thread. Once a thread is detached, it cannot be detached
- // again, nor can it be joined with. Every thread must either be
- // joined with or detached exactly once. Detaching a thread a second
- // time, or detaching a thread that was previously joined with raises
- // ThreadSyscallException.
+ // again, nor can it be joined with. Every thread that was created using
+ // the IceUtil::Thread class must either be joined with or detached
+ // exactly once. Detaching a thread a second time, or detaching a
+ // thread that was previously joined with results in undefined behavior.
//
void detach();
@@ -107,12 +110,11 @@ public:
private:
+ Mutex _stateMutex;
#ifdef _WIN32
HandleWrapperPtr _handle;
#endif
ThreadId _id;
-
- bool _detached;
};
class ICE_UTIL_API Thread : virtual public IceUtil::Shared
@@ -134,10 +136,12 @@ public:
bool operator!=(const Thread&) const;
bool operator<(const Thread&) const;
+ Thread(const Thread&); // Copying is forbidden
+ void operator=(const Thread&); // Assignment is forbidden
+
private:
Mutex _stateMutex;
-
bool _started;
#ifdef _WIN32
HandleWrapperPtr _handle;