]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test. 17592/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 21 Aug 2024 22:28:08 +0000 (16:28 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 21 Aug 2024 22:29:16 +0000 (16:29 -0600)
tests/multithreading/task_result_06.cc [new file with mode: 0644]
tests/multithreading/task_result_06.output [new file with mode: 0644]

diff --git a/tests/multithreading/task_result_06.cc b/tests/multithreading/task_result_06.cc
new file mode 100644 (file)
index 0000000..937b1ee
--- /dev/null
@@ -0,0 +1,53 @@
+// ------------------------------------------------------------------------
+//
+// SPDX-License-Identifier: LGPL-2.1-or-later
+// Copyright (C) 2009 - 2024 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// Part of the source code is dual licensed under Apache-2.0 WITH
+// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
+// governing the source code and code contributions can be found in
+// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
+//
+// ------------------------------------------------------------------------
+
+
+// Test TaskResult::emplace_object().
+
+#include <deal.II/base/task_result.h>
+
+#include "../tests.h"
+
+
+
+int
+main()
+{
+  initlog();
+
+  {
+    // Create a background task that returns a value. Associate this
+    // background task with a TaskResult object.
+    Threads::TaskResult<int> t = Threads::new_task([]() {
+      std::this_thread::sleep_for(std::chrono::seconds(1));
+      return 42;
+    });
+
+    // Wait for that background task to finish, then get its
+    // value:
+    deallog << t.value() << std::endl;
+
+    // Now set things to a different value, and output it:
+    t.emplace_object(43);
+    deallog << t.value() << std::endl;
+  }
+
+  {
+    // Create an empty TaskResult object. Then set its value to
+    // something and check what that is:
+    Threads::TaskResult<int> t;
+    t.emplace_object(44);
+    deallog << t.value() << std::endl;
+  }
+}
diff --git a/tests/multithreading/task_result_06.output b/tests/multithreading/task_result_06.output
new file mode 100644 (file)
index 0000000..4cb8cc1
--- /dev/null
@@ -0,0 +1,4 @@
+
+DEAL::42
+DEAL::43
+DEAL::44

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.