ExcMessage(
"Error: MPI::CollectiveMutex needs to be locked before unlock()"));
+ // Only communicate with other processes if there is no uncaught
+ // exception to avoid a deadlock.
#ifdef DEAL_II_WITH_MPI
-
- // TODO: For now, we implement this mutex with a blocking barrier
- // in the lock and unlock. It needs to be tested, if we can move
- // to a nonblocking barrier (code disabled below):
+# if __cpp_lib_uncaught_exceptions >= 201411
+ // std::uncaught_exception() is deprecated in c++17
+ if (std::uncaught_exceptions() == 0 && comm != MPI_COMM_SELF)
+# else
+ if (std::uncaught_exception() == false && comm != MPI_COMM_SELF)
+# endif
+ {
+ // TODO: For now, we implement this mutex with a blocking barrier
+ // in the lock and unlock. It needs to be tested, if we can move
+ // to a nonblocking barrier (code disabled below):
# if 0
- const int ierr = MPI_Ibarrier(comm, &request);
- AssertThrowMPI(ierr);
+ const int ierr = MPI_Ibarrier(comm, &request);
+ AssertThrowMPI(ierr);
# else
- const int ierr = MPI_Barrier(comm);
- AssertThrowMPI(ierr);
+ const int ierr = MPI_Barrier(comm);
+ AssertThrowMPI(ierr);
# endif
+ }
#endif
+ // Unlock the mutex in either case. Either we successfully
+ // synchronized processes in the barrier, or we want to
+ // continue to unwind the stack without throwing exceptions
+ // in the destructor of this class.
locked = false;
}