From 3d544c5b9cfa7345454d21f3af7fdf5415929dd3 Mon Sep 17 00:00:00 2001 From: bangerth Date: Tue, 6 Apr 2010 15:17:28 +0000 Subject: [PATCH] Sort output in case of thread errors a bit better. git-svn-id: https://svn.dealii.org/trunk@20953 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/source/thread_management.cc | 87 ++++++++++++++++-------- 1 file changed, 57 insertions(+), 30 deletions(-) diff --git a/deal.II/base/source/thread_management.cc b/deal.II/base/source/thread_management.cc index dd30beaef7..a760492b6d 100644 --- a/deal.II/base/source/thread_management.cc +++ b/deal.II/base/source/thread_management.cc @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009 by the deal.II authors +// Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -35,6 +35,7 @@ # include #endif + DEAL_II_NAMESPACE_OPEN @@ -68,21 +69,36 @@ namespace Threads void handle_std_exception (const std::exception &exc) { - std::cerr << std::endl << std::endl - << "---------------------------------------------------------" - << std::endl - << "In one of the sub-threads of this program, an exception\n" - << "was thrown and not caught. Since exceptions do not\n" - << "propagate to the main thread, the library has caught it.\n" - << "The information carried by this exception is given below.\n" - << std::endl - << "---------------------------------------------------------" - << std::endl; - std::cerr << "Exception on processing: " << std::endl - << exc.what() << std::endl - << "Aborting!" << std::endl - << "---------------------------------------------------------" - << std::endl; + // lock the following context + // to ensure that we don't + // print things over each other + // if we have trouble from + // multiple threads. release + // the lock before calling + // std::abort, though + static Mutex mutex; + { + Mutex::ScopedLock lock(mutex); + + std::cerr << std::endl << std::endl + << "---------------------------------------------------------" + << std::endl + << "In one of the sub-threads of this program, an exception\n" + << "was thrown and not caught. Since exceptions do not\n" + << "propagate to the main thread, the library has caught it.\n" + << "The information carried by this exception is given below.\n" + << std::endl + << "---------------------------------------------------------" + << std::endl; + std::cerr << "Exception message: " << std::endl + << " " << exc.what() << std::endl + << "Exception type: " << std::endl + << " " << typeid(exc).name() << std::endl; + std::cerr << "Aborting!" << std::endl + << "---------------------------------------------------------" + << std::endl; + } + std::abort (); } @@ -90,20 +106,31 @@ namespace Threads void handle_unknown_exception () { - std::cerr << std::endl << std::endl - << "---------------------------------------------------------" - << std::endl - << "In one of the sub-threads of this program, an exception\n" - << "was thrown and not caught. Since exceptions do not\n" - << "propagate to the main thread, the library has caught it.\n" - << "The information carried by this exception is given below.\n" - << std::endl - << "---------------------------------------------------------" - << std::endl; - std::cerr << "Type of exception is unknown, but not std::exception.\n" - << "No additional information is available.\n" - << "---------------------------------------------------------" - << std::endl; + // lock the following context + // to ensure that we don't + // print things over each other + // if we have trouble from + // multiple threads. release + // the lock before calling + // std::abort, though + static Mutex mutex; + { + Mutex::ScopedLock lock(mutex); + + std::cerr << std::endl << std::endl + << "---------------------------------------------------------" + << std::endl + << "In one of the sub-threads of this program, an exception\n" + << "was thrown and not caught. Since exceptions do not\n" + << "propagate to the main thread, the library has caught it.\n" + << std::endl + << "---------------------------------------------------------" + << std::endl; + std::cerr << "Type of exception is unknown, but not std::exception.\n" + << "No additional information is available.\n" + << "---------------------------------------------------------" + << std::endl; + } std::abort (); } } -- 2.39.5