From 1186f4058ab745f38dba3f9ccf2192156e4a2934 Mon Sep 17 00:00:00 2001 From: wolf Date: Fri, 23 Feb 2001 09:17:06 +0000 Subject: [PATCH] Make (un)subscription thread safe. This generated false exceptions in 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 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/deal.II/base/source/subscriptor.cc b/deal.II/base/source/subscriptor.cc index 9821173945..77c48e0467 100644 --- a/deal.II/base/source/subscriptor.cc +++ b/deal.II/base/source/subscriptor.cc @@ -12,9 +12,26 @@ //---------------------------- subscriptor.cc --------------------------- +#include #include #include +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 file into the +// file). + Threads::ThreadMutex subscription_lock; +}; + + + /* #include @@ -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(); }; -- 2.39.5