--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 - 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Verify that we can create tasks both via lambdas that take
+// arguments, and then passing these arguments as follow-up arguments
+// to new_task(). In other words, this is the equivalent strategy to
+// passing a function pointer as the first argument, and the arguments
+// to the function following.
+//
+// task_13 already checks the case of lambda functions that take no
+// arguments.
+
+
+#include <deal.II/base/thread_management.h>
+
+#include "../tests.h"
+
+
+// return a double, to make sure we correctly identify the return type
+// of the expressions used in new_task(...)
+double
+test(int i)
+{
+ deallog << "Task " << i << " starting..." << std::endl;
+ std::this_thread::sleep_for(std::chrono::seconds(1));
+ deallog << "Task " << i << " finished!" << std::endl;
+
+ return 3.141;
+}
+
+
+
+int
+main()
+{
+ initlog();
+
+ Threads::TaskGroup<double> tg;
+
+ // use variations of ways we can declare lambdas
+ tg += Threads::new_task([](int i) -> double { return test(i); }, 1);
+ tg += Threads::new_task([](int i) -> double { return (float)test(i); }, 2);
+
+ tg.join_all();
+
+ deallog << "OK" << std::endl;
+
+ std::ofstream *out_stream =
+ dynamic_cast<std::ofstream *>(&deallog.get_file_stream());
+ Assert(out_stream != nullptr, ExcInternalError());
+ deallog.detach();
+ out_stream->close();
+ sort_file_contents("output");
+}
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 - 2022 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 _15 test, but check that arguments are properly copied.
+
+
+#include <deal.II/base/thread_management.h>
+
+#include "../tests.h"
+
+
+// return a double, to make sure we correctly identify the return type
+// of the expressions used in new_task(...)
+int
+test(int i)
+{
+ return 2 * i;
+}
+
+
+
+int
+main()
+{
+ initlog();
+
+ // Create a bunch of tasks, and put them into a TaskGroup. The test
+ // also checks that the call to `new_task()` needs to copy the
+ // passed in value for `i` rather than take a reference to it,
+ // because it would otherwise use outdated values.
+ Threads::TaskGroup<int> tg;
+ for (unsigned int i = 0; i < 10; ++i)
+ tg += Threads::new_task([](int ii) { return test(ii); }, i);
+
+ // Then wait for them all to finish and output their respective
+ // return values. They should be ordered the same way the tasks were
+ // created, and should be twice the input argument:
+ for (const int r : tg.return_values())
+ deallog << r << std::endl;
+}