]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make (un)subscription thread safe. This generated false exceptions in
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 23 Feb 2001 09:17:06 +0000 (09:17 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Fri, 23 Feb 2001 09:17:06 +0000 (09:17 +0000)
some rare cases (hmph, very untractable things...)

git-svn-id: https://svn.dealii.org/trunk@4021 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/source/subscriptor.cc

index 9821173945e9d559651e59323cec9b730cd04f7d..77c48e04673cbcfadc75652d39bc60cfe9fed302 100644 (file)
 //----------------------------  subscriptor.cc  ---------------------------
 
 
+#include <base/thread_management.h>
 #include <base/subscriptor.h>
 #include <typeinfo>
 
+namespace 
+{
+// create a lock that might be used to control subscription to and
+// unsubscription from objects, as that might happen in parallel.
+// since it should happen rather seldom that several threads try to
+// operate on different objects at the same time (the usual case is
+// that they subscribe to the same object right after thread
+// creation), a global lock should be sufficient, rather than one that
+// operates on a per-object base (in which case we would have to
+// include the huge <thread_management.h> file into the
+// <subscriptor.h> file).
+  Threads::ThreadMutex subscription_lock;
+};
+
+
+
 /*
 #include <set>
 
@@ -112,13 +129,17 @@ void Subscriptor::subscribe () const
     object_info = &typeid(*this);
 #endif
 
+  subscription_lock.acquire();
   ++counter;
+  subscription_lock.release();
 };
 
 
 void Subscriptor::unsubscribe () const {
   Assert (counter>0, ExcNotUsed());
+  subscription_lock.acquire();
   --counter;
+  subscription_lock.release();
 };
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.