]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a barrier class to the Threads:: namespace.
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 19 Mar 2001 15:05:55 +0000 (15:05 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Mon, 19 Mar 2001 15:05:55 +0000 (15:05 +0000)
git-svn-id: https://svn.dealii.org/trunk@4244 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/thread_management.h
deal.II/base/source/thread_management.cc

index 0a5ab9eaec3a9e0560bfd08cb9cdb7cb153389a9..89b7973e938bf7688ec6cde165d642759cdf7672 100644 (file)
@@ -117,16 +117,78 @@ namespace Threads
       inline void wait () const {};
   };
 
+
+  
+/**
+ * This class is used instead of a true barrier class when not using
+ * multithreading. It allows to write programs such that they use the
+ * same class names in multithreading and non-MT mode and thus may be
+ * compiled with or without thread-support without the need to use
+ * conditional compilation. Since a barrier class only makes sense in
+ * non-multithread mode if only one thread is to be synchronised
+ * (otherwise, the barrier could not be left, since the one thread is
+ * waiting for some other part of the program to reach a certain point
+ * of execution), the constructor of this class throws an exception if
+ * the @p{count} argument denoting the number of threads that need to
+ * be synchronised is not equal to one.
+ *
+ * @author Wolfgang Bangerth, 2001
+ */
+  class DummyBarrier
+  {
+    public:
+                                      /**
+                                       * Constructor. Since barriers
+                                       * are only useful in
+                                       * single-threaded mode if the
+                                       * number of threads to be
+                                       * synchronised is one, this
+                                       * constructor raises an
+                                       * exception if the @p{count}
+                                       * argument is one.
+                                       */
+      DummyBarrier (const unsigned int  count,
+                   const char         *name = 0,
+                   void               *arg  = 0);
+
+                                      /**
+                                       * Wait for all threads to
+                                       * reach this point. Since
+                                       * there may only be one
+                                       * thread, return immediately,
+                                       * i.e. this function is a
+                                       * no-op.
+                                       */
+      int wait () { return 0; };
+
+                                      /**
+                                       * Dump the state of this
+                                       * object. Here: do nothing.
+                                       */
+      void dump () {};
+
+                                      /**
+                                       * Exception.
+                                       */
+      DeclException1 (ExcBarrierSizeNotUseful,
+                     int,
+                     << "In single-thread mode, other barrier sizes than 1 are not "
+                     << "useful. You gave " << arg1);
+  };
+  
   
 #ifdef DEAL_II_USE_MT
                                   /**
                                    * In multithread mode, we alias
                                    * the mutex and thread management
                                    * classes to the respective
-                                   * classes of the ACE library.
+                                   * classes of the ACE
+                                   * library. Likewise for the
+                                   * barrier class.
                                    */
   typedef ACE_Thread_Mutex   ThreadMutex;
   typedef ACE_Thread_Manager ThreadManager;
+  typedef ACE_Barrier        Barrier;
 #else
                                   /**
                                    * In non-multithread mode, the
@@ -134,10 +196,13 @@ namespace Threads
                                    * classes are aliased to dummy
                                    * classes that actually do
                                    * nothing, in particular not lock
-                                   * objects or start new threads.
+                                   * objects or start new
+                                   * threads. Likewise for the
+                                   * barrier class.
                                    */
   typedef DummyThreadMutex   ThreadMutex;
   typedef DummyThreadManager ThreadManager;
+  typedef DummyBarrier       Barrier;
 #endif
 
   
index 801cdee5c23a92820fffe5caa463c4b8e4d2242b..8b1430eea211dac14fe2f4b617e1f34bcd1d5266 100644 (file)
@@ -27,6 +27,15 @@ namespace Threads
   
 
   
+  DummyBarrier::DummyBarrier (const unsigned int  count,
+                             const char         *,
+                             void               *)
+  {
+    Assert (count == 1, ExcBarrierSizeNotUseful(count));
+  };
+
+  
+  
   FunDataCounter::FunDataCounter () :
                  n_fun_encapsulation_objects (0),
                  n_fun_data_base_objects (0)

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.