summaryrefslogtreecommitdiff
path: root/ace/Thread_Manager.cpp
diff options
context:
space:
mode:
authornanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-06-01 22:07:53 +0000
committernanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-06-01 22:07:53 +0000
commitf237ccbb8414a63231dbef45df8fb42b48a3b923 (patch)
tree0480fc2a840f47762f1ecff517f99240fbae51e0 /ace/Thread_Manager.cpp
parent7ea34bd80216c224677ced47de722c0a79be4913 (diff)
downloadATCD-f237ccbb8414a63231dbef45df8fb42b48a3b923.tar.gz
Modified double-checking pattern
Diffstat (limited to 'ace/Thread_Manager.cpp')
-rw-r--r--ace/Thread_Manager.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/ace/Thread_Manager.cpp b/ace/Thread_Manager.cpp
index e357c037266..a52d6132731 100644
--- a/ace/Thread_Manager.cpp
+++ b/ace/Thread_Manager.cpp
@@ -17,6 +17,9 @@ ACE_ALLOC_HOOK_DEFINE(ACE_Thread_Manager)
// Process-wide Thread Manager.
ACE_Thread_Manager *ACE_Thread_Manager::thr_mgr_ = 0;
+// Flag that ensures accessing <thr_mgr_> is an MP safe op.
+int ACE_Thread_Manager::instantiated_ = 0;
+
// Controls whether the Thread_Manager is deleted when we shut down
// (we can only delete it safely if we created it!)
int ACE_Thread_Manager::delete_thr_mgr_ = 0;
@@ -216,16 +219,17 @@ ACE_Thread_Manager::instance (void)
{
ACE_TRACE ("ACE_Thread_Manager::instance");
- if (ACE_Thread_Manager::thr_mgr_ == 0)
+ if (ACE_Thread_Manager::instantiated_ == 0)
{
// Perform Double-Checked Locking Optimization.
ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
*ACE_Static_Object_Lock::instance (), 0));
- if (ACE_Thread_Manager::thr_mgr_ == 0)
+ if (ACE_Thread_Manager::instantiated_ == 0)
{
ACE_NEW_RETURN (ACE_Thread_Manager::thr_mgr_, ACE_Thread_Manager, 0);
ACE_Thread_Manager::delete_thr_mgr_ = 1;
+ ACE_Thread_Manager::instantiated_ = -1;
}
}
@@ -244,6 +248,9 @@ ACE_Thread_Manager::instance (ACE_Thread_Manager *tm)
ACE_Thread_Manager::delete_thr_mgr_ = 0;
ACE_Thread_Manager::thr_mgr_ = tm;
+
+ ACE_Thread_Manager::instantiated_ = (tm != 0 ? -1 : 0);
+
return t;
}
@@ -260,6 +267,7 @@ ACE_Thread_Manager::close_singleton (void)
// First, we clean up the thread descriptor list.
ACE_Thread_Manager::thr_mgr_->close ();
delete ACE_Thread_Manager::thr_mgr_;
+ ACE_Thread_Manager::instantiated_= 0;
ACE_Thread_Manager::thr_mgr_ = 0;
ACE_Thread_Manager::delete_thr_mgr_ = 0;
}