diff --git a/test/tbb/test_task.cpp b/test/tbb/test_task.cpp index 927c841033..6c2060a69a 100644 --- a/test/tbb/test_task.cpp +++ b/test/tbb/test_task.cpp @@ -861,3 +861,44 @@ TEST_CASE("Try to force Leaked proxy observers warning") { }); }); } + +//! \brief \ref error_guessing +TEST_CASE("Force thread limit on per-thread reference_vertex") { + int num_threads = std::thread::hardware_concurrency(); + int num_groups = 1000; + + // Force thread limit on per-thread reference_vertex + std::vector groups(num_groups); + tbb::parallel_for(0, num_threads, [&] (int) { + std::vector local_groups(num_groups); + for (int i = 0; i < num_groups; ++i) { + groups[i].run([] {}); + local_groups[i].run([] {}); + local_groups[i].wait(); + } + }, tbb::static_partitioner{}); + + // Enforce extra reference on each task_group + std::deque handles{}; + for (int i = 0; i < num_groups; ++i) { + handles.emplace_back(groups[i].defer([] {})); + } + + // Check correctness of the execution + tbb::task_group group; + + std::atomic final_sum{}; + for (int i = 0; i < num_groups; ++i) { + group.run([&] { ++final_sum; }); + } + group.wait(); + REQUIRE_MESSAGE(final_sum == num_groups, "Some tasks were not executed"); + + for (int i = 0; i < num_groups; ++i) { + groups[i].run(std::move(handles[i])); + } + + for (int i = 0; i < num_groups; ++i) { + groups[i].wait(); + } +}