summaryrefslogtreecommitdiff
path: root/cpp/src/IceUtil/Thread.cpp
diff options
context:
space:
mode:
authorMichi Henning <michi@zeroc.com>2003-03-10 06:29:41 +0000
committerMichi Henning <michi@zeroc.com>2003-03-10 06:29:41 +0000
commite512a2677f0b556c5d29803361e5527f05622911 (patch)
treeb948aa9e594f6b96f90eb006bc4ae4b1cfad3d73 /cpp/src/IceUtil/Thread.cpp
parentFixed a variety of race conditions in Thread.cpp. Made RWRecMutex smaller. (diff)
downloadice-e512a2677f0b556c5d29803361e5527f05622911.tar.bz2
ice-e512a2677f0b556c5d29803361e5527f05622911.tar.xz
ice-e512a2677f0b556c5d29803361e5527f05622911.zip
Got rid of race conditions for Thread comparison.
Diffstat (limited to 'cpp/src/IceUtil/Thread.cpp')
-rw-r--r--cpp/src/IceUtil/Thread.cpp132
1 files changed, 96 insertions, 36 deletions
diff --git a/cpp/src/IceUtil/Thread.cpp b/cpp/src/IceUtil/Thread.cpp
index 3ad29cecda3..ad7782a49f4 100644
--- a/cpp/src/IceUtil/Thread.cpp
+++ b/cpp/src/IceUtil/Thread.cpp
@@ -218,60 +218,90 @@ IceUtil::Thread::getThreadControl() const
bool
IceUtil::Thread::operator==(const Thread& rhs) const
{
+ //
+ // Check that this thread was started.
+ //
{
IceUtil::Mutex::Lock lock(_stateMutex);
if(!_started)
{
throw ThreadNotStartedException(__FILE__, __LINE__);
}
- }
+ } // Release lock, to avoid mutual deadlock between this thread and rhs.
+
+ //
+ // Check that the rhs thread was started.
+ //
+ IceUtil::Mutex::Lock lock(rhs._stateMutex);
+ if(!rhs._started)
{
- IceUtil::Mutex::Lock lock(rhs._stateMutex);
- if(!rhs._started)
- {
- throw ThreadNotStartedException(__FILE__, __LINE__);
- }
+ throw ThreadNotStartedException(__FILE__, __LINE__);
}
+
+ //
+ // We perform the comparison within the scope of the lock, otherwise the hardware has no
+ // way of knowing that it might have to flush a cache line.
+ //
return _id == rhs._id;
}
bool
IceUtil::Thread::operator!=(const Thread& rhs) const
{
+ //
+ // Check that this thread was started.
+ //
{
IceUtil::Mutex::Lock lock(_stateMutex);
if(!_started)
{
throw ThreadNotStartedException(__FILE__, __LINE__);
}
- }
+ } // Release lock, to avoid mutual deadlock between this thread and rhs.
+
+ //
+ // Check that the rhs thread was started.
+ //
+ IceUtil::Mutex::Lock lock(rhs._stateMutex);
+ if(!rhs._started)
{
- IceUtil::Mutex::Lock lock(rhs._stateMutex);
- if(!rhs._started)
- {
- throw ThreadNotStartedException(__FILE__, __LINE__);
- }
+ throw ThreadNotStartedException(__FILE__, __LINE__);
}
+
+ //
+ // We perform the comparison within the scope of the lock, otherwise the hardware has no
+ // way of knowing that it might have to flush a cache line.
+ //
return _id != rhs._id;
}
bool
IceUtil::Thread::operator<(const Thread& rhs) const
{
+ //
+ // Check that this thread was started.
+ //
{
IceUtil::Mutex::Lock lock(_stateMutex);
if(!_started)
{
throw ThreadNotStartedException(__FILE__, __LINE__);
}
- }
+ } // Release lock, to avoid mutual deadlock between this thread and rhs.
+
+ //
+ // Check that the rhs thread was started.
+ //
+ IceUtil::Mutex::Lock lock(rhs._stateMutex);
+ if(!rhs._started)
{
- IceUtil::Mutex::Lock lock(rhs._stateMutex);
- if(!rhs._started)
- {
- throw ThreadNotStartedException(__FILE__, __LINE__);
- }
+ throw ThreadNotStartedException(__FILE__, __LINE__);
}
+
+ //
+ // We perform the comparison within the scope of the lock, otherwise the hardware has no
+ // way of knowing that it might have to flush a cache line.
+ //
return _id < rhs._id;
}
@@ -465,61 +495,91 @@ IceUtil::Thread::getThreadControl() const
bool
IceUtil::Thread::operator==(const Thread& rhs) const
{
+ //
+ // Check that this thread was started.
+ //
{
IceUtil::Mutex::Lock lock(_stateMutex);
if(!_started)
{
throw ThreadNotStartedException(__FILE__, __LINE__);
}
- }
+ } // Release lock, to avoid mutual deadlock between this thread and rhs.
+
+ //
+ // Check that the rhs thread was started.
+ //
+ IceUtil::Mutex::Lock lock(rhs._stateMutex);
+ if(!rhs._started)
{
- IceUtil::Mutex::Lock lock(rhs._stateMutex);
- if(!rhs._started)
- {
- throw ThreadNotStartedException(__FILE__, __LINE__);
- }
+ throw ThreadNotStartedException(__FILE__, __LINE__);
}
+
+ //
+ // We perform the comparison within the scope of the lock, otherwise the hardware has no
+ // way of knowing that it might have to flush a cache line.
+ //
return pthread_equal(_id, rhs._id);
}
bool
IceUtil::Thread::operator!=(const Thread& rhs) const
{
+ //
+ // Check that this thread was started.
+ //
{
IceUtil::Mutex::Lock lock(_stateMutex);
if(!_started)
{
throw ThreadNotStartedException(__FILE__, __LINE__);
}
- }
+ } // Release lock, to avoid mutual deadlock between this thread and rhs.
+
+ //
+ // Check that the rhs thread was started.
+ //
+ IceUtil::Mutex::Lock lock(rhs._stateMutex);
+ if(!rhs._started)
{
- IceUtil::Mutex::Lock lock(rhs._stateMutex);
- if(!rhs._started)
- {
- throw ThreadNotStartedException(__FILE__, __LINE__);
- }
+ throw ThreadNotStartedException(__FILE__, __LINE__);
}
+
+ //
+ // We perform the comparison within the scope of the lock, otherwise the hardware has no
+ // way of knowing that it might have to flush a cache line.
+ //
return !pthread_equal(_id, rhs._id);
}
bool
IceUtil::Thread::operator<(const Thread& rhs) const
{
+ //
+ // Check that this thread was started.
+ //
{
IceUtil::Mutex::Lock lock(_stateMutex);
if(!_started)
{
throw ThreadNotStartedException(__FILE__, __LINE__);
}
- }
+ } // Release lock, to avoid mutual deadlock between this thread and rhs.
+
+ //
+ // Check that the rhs thread was started.
+ //
+ IceUtil::Mutex::Lock lock(rhs._stateMutex);
+ if(!rhs._started)
{
- IceUtil::Mutex::Lock lock(rhs._stateMutex);
- if(!rhs._started)
- {
- throw ThreadNotStartedException(__FILE__, __LINE__);
- }
+ throw ThreadNotStartedException(__FILE__, __LINE__);
}
+ //
+ // We perform the comparison within the scope of the lock, otherwise the hardware has no
+ // way of knowing that it might have to flush a cache line.
+ //
// NOTE: Linux specific
+ //
return _id < rhs._id;
}