]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test.
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 30 Jun 2023 17:42:49 +0000 (11:42 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sun, 2 Jul 2023 02:38:35 +0000 (20:38 -0600)
tests/multithreading/task_01_exception_03.cc [new file with mode: 0644]
tests/multithreading/task_01_exception_03.output [new file with mode: 0644]

diff --git a/tests/multithreading/task_01_exception_03.cc b/tests/multithreading/task_01_exception_03.cc
new file mode 100644 (file)
index 0000000..124ee8f
--- /dev/null
@@ -0,0 +1,69 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2009 - 2020 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+// Like the _01 test, but check that if the function called on the
+// task throws an exception, that Task::wait() continues to work but
+// Task::return_value() throws the exception.
+//
+// While Task::return_value() throws an exception the first time
+// around, this won't happen the second time around because the stored
+// exception is already gone. But the return value has not been
+// initialized in that case, and so you just aren't allowed to call
+// return_value() a second time. This test checks that.
+
+#include <deal.II/base/thread_management.h>
+
+#include "../tests.h"
+
+
+int
+test()
+{
+  std::this_thread::sleep_for(std::chrono::seconds(3));
+
+  throw 42;
+}
+
+
+int
+main()
+{
+  initlog();
+
+  Threads::Task<int> t = Threads::new_task(test);
+
+  // Here, an exception should be triggered:
+  try
+    {
+      t.return_value();
+    }
+  catch (int i)
+    {
+      Assert(i == 42, ExcInternalError());
+      deallog << "OK" << std::endl;
+    }
+
+  // This must fail:
+  deal_II_exceptions::disable_abort_on_exception();
+  try
+    {
+      t.return_value();
+    }
+  catch (const ExcMessage &)
+    {
+      deallog << "Expected exception." << std::endl;
+    }
+}
diff --git a/tests/multithreading/task_01_exception_03.output b/tests/multithreading/task_01_exception_03.output
new file mode 100644 (file)
index 0000000..24f870f
--- /dev/null
@@ -0,0 +1,3 @@
+
+DEAL::OK
+DEAL::Expected exception.

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.