simultaneous_function_spawner_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (simultaneous_function_spawner test)
3 
5 
6 BOOST_AUTO_TEST_SUITE(simultaneous_function_spawner)
7 
9 {
10  auto task = [] { std::cout << "Hello concurrent world.\n"; };
12 }
13 
15 {
16  std::atomic<int> i{1};
17  auto task = [&i] { ++i; };
19  BOOST_TEST(i == 8);
20 }
21 
22 BOOST_AUTO_TEST_CASE(assign_different_numbers)
23 {
24  std::vector<int> nums(7); // All 7 numbers initialized to 0.
25  std::vector<std::function<void()>> tasks;
26  tasks.push_back([&nums] { nums[0] = 1; });
27  tasks.push_back([&nums] { nums[1] = 3; });
28  tasks.push_back([&nums] { nums[2] = 5; });
29  tasks.push_back([&nums] { nums[3] = 7; });
30  tasks.push_back([&nums] { nums[4] = 6; });
31  tasks.push_back([&nums] { nums[5] = 4; });
32  tasks.push_back([&nums] { nums[6] = 2; });
33  auto const ref = {1, 3, 5, 7, 6, 4, 2};
35  BOOST_TEST(nums == ref, boost::test_tools::per_element{});
36 }
37 
38 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(cout)
auto repeated_task(std::size_t const nInstances, F func)