Skip to content

Commit 1f3cf47

Browse files
committed
Check for exception unwinding in ~LibMeshInit
I don't know of any compilers that unwind before terminate(), but the standard says it's allowed and we don't want to hang if it happens.
1 parent 5957c54 commit 1f3cf47

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/base/libmesh.C

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,14 +829,21 @@ LibMeshInit::LibMeshInit (int argc, const char * const * argv,
829829
LibMeshInit::~LibMeshInit()
830830
{
831831
// Every processor had better be ready to exit at the same time.
832-
// This would be a libmesh_parallel_only() function, except that
833-
// libmesh_parallel_only() uses libmesh_assert() which throws an
834-
// exception() which causes compilers to scream about exceptions
835-
// inside destructors.
836-
837832
// Even if we're not doing parallel_only debugging, we don't want
838833
// one processor to try to exit until all others are done working.
839-
this->comm().barrier();
834+
835+
// We could be destructing here because we're unwinding the stack
836+
// due to a thrown exception, though. It's possible that an
837+
// application is catching exceptions outside of the LibMeshInit
838+
// scope, or that we're using a C++ compiler that does unwinding
839+
// for uncaught exceptions (the standard says whether to go straight
840+
// to terminate() or unwind first is "implementation-defined"). If
841+
// *that* is the case then we can't safely communicate with other
842+
// processors that might not all be unwinding too.
843+
#ifdef LIBMESH_ENABLE_EXCEPTIONS
844+
if (std::uncaught_exceptions())
845+
#endif
846+
this->comm().barrier();
840847

841848
// We can't delete, finalize, etc. more than once without
842849
// reinitializing in between

0 commit comments

Comments
 (0)