diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/IceUtil/Thread.h | 2 | ||||
-rw-r--r-- | cpp/src/IceUtil/Thread.cpp | 24 |
2 files changed, 19 insertions, 7 deletions
diff --git a/cpp/include/IceUtil/Thread.h b/cpp/include/IceUtil/Thread.h index 05278771089..a99ee76003c 100644 --- a/cpp/include/IceUtil/Thread.h +++ b/cpp/include/IceUtil/Thread.h @@ -90,12 +90,12 @@ public: private: #ifdef _WIN32 - bool _detached; HandleWrapperPtr _handle; unsigned _id; #else pthread_t _id; #endif + bool _detached; }; class ICE_UTIL_API Thread : virtual public IceUtil::Shared diff --git a/cpp/src/IceUtil/Thread.cpp b/cpp/src/IceUtil/Thread.cpp index 067bd721d76..5a7d8a33c4b 100644 --- a/cpp/src/IceUtil/Thread.cpp +++ b/cpp/src/IceUtil/Thread.cpp @@ -22,8 +22,8 @@ using namespace std; IceUtil::ThreadControl::ThreadControl() : _handle(new HandleWrapper(0)), - _detached(false), - _id(GetCurrentThreadId()) + _id(GetCurrentThreadId()), + _detached(false) { HANDLE proc = GetCurrentProcess(); HANDLE current = GetCurrentThread(); @@ -36,8 +36,8 @@ IceUtil::ThreadControl::ThreadControl() : IceUtil::ThreadControl::ThreadControl(const HandleWrapperPtr& handle, unsigned id) : _handle(handle), - _detached(false), - _id(id) + _id(id), + _detached(false) { } @@ -212,12 +212,14 @@ IceUtil::Thread::operator<(const Thread& rhs) const #else IceUtil::ThreadControl::ThreadControl(pthread_t id) : - _id(id) + _id(id), + _detached(false) { } IceUtil::ThreadControl::ThreadControl() : - _id(pthread_self()) + _id(pthread_self()), + _detached(false) { } @@ -245,6 +247,11 @@ IceUtil::ThreadControl::join() { if(_id) { + if (_detached) + { + throw ThreadSyscallException(__FILE__, __LINE__); + } + _detached = true; void* ignore = 0; int rc = pthread_join(_id, &ignore); if(rc != 0) @@ -259,6 +266,11 @@ IceUtil::ThreadControl::detach() { if(_id) { + if (_detached) + { + throw ThreadSyscallException(__FILE__, __LINE__); + } + _detached = true; int rc = pthread_detach(_id); if(rc != 0) { |