From: wolf Date: Thu, 5 Sep 2002 20:44:26 +0000 (+0000) Subject: Lift restriction on use of Threads::PosixThreadBarrier slightly for the case that... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2beaa13f2469a7e94c898891a0817a30b6f2df52;p=dealii-svn.git Lift restriction on use of Threads::PosixThreadBarrier slightly for the case that the respective POSIX functions are not available. git-svn-id: https://svn.dealii.org/trunk@6368 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/thread_management.h b/deal.II/base/include/base/thread_management.h index 37de73f7dd..8dc20c2fa7 100644 --- a/deal.II/base/include/base/thread_management.h +++ b/deal.II/base/include/base/thread_management.h @@ -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 }; diff --git a/deal.II/base/source/thread_management.cc b/deal.II/base/source/thread_management.cc index c198e19b8c..dccdd02e3b 100644 --- a/deal.II/base/source/thread_management.cc +++ b/deal.II/base/source/thread_management.cc @@ -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 }; diff --git a/deal.II/doc/news/2002/c-3-4.html b/deal.II/doc/news/2002/c-3-4.html index 7b6e5c8c02..1563bac598 100644 --- a/deal.II/doc/news/2002/c-3-4.html +++ b/deal.II/doc/news/2002/c-3-4.html @@ -95,6 +95,19 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK

base

    +
  1. + Extended: Previously, the Threads::PosixThreadBarrier + 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. +
    + (WB 2002/09/05) +

    +
  2. New: The old class vector2d, implementing a two-dimensional array of objects is now gone. Instead, there is the new