]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Lift restriction on use of Threads::PosixThreadBarrier slightly for the case that...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 5 Sep 2002 20:44:26 +0000 (20:44 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 5 Sep 2002 20:44:26 +0000 (20:44 +0000)
git-svn-id: https://svn.dealii.org/trunk@6368 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/thread_management.h
deal.II/base/source/thread_management.cc
deal.II/doc/news/2002/c-3-4.html

index 37de73f7dd87267e28573bd7556f9a274151adbf..8dc20c2fa76cabe4848dac4a4cd96dd65e45d942 100644 (file)
@@ -246,15 +246,25 @@ namespace Threads
                                    * POSIX thread functions. POSIX
                                    * barriers are a relatively new
                                    * feature and are not supported on
-                                   * all systems. If the
-                                   * configuration detected the
-                                   * absence of these functions, then
-                                   * barriers will not be available,
-                                   * and creating objects of this
-                                   * class will result in an
-                                   * exception been thrown. The rest
-                                   * of the threading functionality
-                                   * will be available, though.
+                                   * all systems.
+                                   *
+                                   * If the configuration detected
+                                   * the absence of these functions,
+                                   * then barriers will not be
+                                   * available, and creating objects
+                                   * of this class will result in an
+                                   * exception been thrown unless the
+                                   * count given for the parties
+                                   * waiting for the barrier is equal
+                                   * to one (as in this case waiting
+                                   * for the barrier is a
+                                   * no-operation, and we can
+                                   * dispense with the POSIX
+                                   * functions at all). The rest of
+                                   * the threading functionality will
+                                   * be available in its full extent,
+                                   * though, even if POSIX barriers
+                                   * are not available.
                                    *
                                    * @author Wolfgang Bangerth, 2002
                                    */
@@ -298,6 +308,8 @@ namespace Threads
                                        */
 #ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS
       pthread_barrier_t barrier;
+#else
+      unsigned int count;
 #endif
   };
 
index c198e19b8c452c479a4ff73f6c2e67f095715868..dccdd02e3bbf1858f5e877fa6227f7b4ec25d622 100644 (file)
@@ -64,11 +64,18 @@ namespace Threads
 
 #else
 
-  PosixThreadBarrier::PosixThreadBarrier (const unsigned int  ,
+  PosixThreadBarrier::PosixThreadBarrier (const unsigned int  count,
                                          const char         *,
                                          void               *)
+                  : count (count)
   {
-    AssertThrow (false,
+                                     // throw an exception unless we
+                                     // have the special case that a
+                                     // count of 1 is given, since
+                                     // then waiting for a barrier is
+                                     // a no-op, and we don't need the
+                                     // POSIX functionality
+    AssertThrow (count == 1,
                 ExcMessage ("Your local POSIX installation does not support\n"
                             "POSIX barriers. You will not be able to use\n"
                             "this class, but the rest of the threading\n"
@@ -83,7 +90,11 @@ namespace Threads
 #ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS
     pthread_barrier_destroy (&barrier);
 #else
-    std::abort ();
+                                     // unless the barrier is a no-op,
+                                     // complain again (how did we get
+                                     // here then?)
+    if (count != 1)
+      std::abort ();
 #endif
   };
 
@@ -95,8 +106,17 @@ namespace Threads
 #ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS    
     return pthread_barrier_wait (&barrier);
 #else
-    std::abort ();
-    return 1;
+                                     // in the special case, this
+                                     // function is a no-op. otherwise
+                                     // complain about the missing
+                                     // POSIX functions
+    if (count == 1)
+      return 0;
+    else
+      {
+        std::abort ();
+        return 1;
+      };
 #endif
   };
   
index 7b6e5c8c02db560ebaa45e0ae9a1714c292729ad..1563bac5980111d4dfec2293b307b58866d2c41c 100644 (file)
@@ -95,6 +95,19 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
 <h3>base</h3>
 
 <ol>
+  <li> <p> 
+       Extended: Previously, the <code class="class">Threads::PosixThreadBarrier</code>
+       class could not be used at all (they threw exceptions), if your system
+       did not have the respective POSIX functions. This restriction is lifted
+       for the special case that you give one as the number of parties that
+       will be waiting for the barrier: in this case, a barrier is a
+       no-operation, so we do not need assistence from the operating
+       system. This change makes it slightly simpler to write programs in a way
+       such that they run in both single- and multithreaded environments.
+       <br>
+       (WB 2002/09/05)
+       </p>
+
   <li> <p> 
        New: The old class <code class="class">vector2d</code>, implementing a
        two-dimensional array of objects is now gone. Instead, there is the new

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.