|
48 | 48 | //! \file test_task_arena.cpp |
49 | 49 | //! \brief Test for [scheduler.task_arena scheduler.task_scheduler_observer] specification |
50 | 50 |
|
| 51 | +//--------------------------------------------------// |
| 52 | +// Validation function to check that current_thread_index() and execution_slot() return |
| 53 | +// the same value for a thread running within initialized task_arena. The exported function |
| 54 | +// tbb::detail::r1::execution_slot is maintained for backwards compatibility only. |
| 55 | +void check_slot_compatibility(int expected_idx, const tbb::task_arena& arena) { |
| 56 | + int execution_slot_idx = int(tbb::detail::r1::execution_slot(arena)); |
| 57 | + CHECK_MESSAGE(expected_idx == execution_slot_idx, |
| 58 | + "current_thread_index() and execution_slot() should return the same value"); |
| 59 | +} |
| 60 | + |
51 | 61 | //--------------------------------------------------// |
52 | 62 | // Test that task_arena::initialize and task_arena::terminate work when doing nothing else. |
53 | 63 | /* maxthread is treated as the biggest possible concurrency level. */ |
@@ -449,6 +459,7 @@ class TestArenaConcurrencyBody : utils::NoAssign { |
449 | 459 | // Arena's functor |
450 | 460 | void operator()() const { |
451 | 461 | int idx = tbb::this_task_arena::current_thread_index(); |
| 462 | + check_slot_compatibility(idx, my_a); |
452 | 463 | REQUIRE( idx < (my_max_concurrency > 1 ? my_max_concurrency : 2) ); |
453 | 464 | REQUIRE( my_a.max_concurrency() == tbb::this_task_arena::max_concurrency() ); |
454 | 465 | int max_arena_concurrency = tbb::this_task_arena::max_concurrency(); |
@@ -588,6 +599,7 @@ struct TaskArenaValidator { |
588 | 599 | void operator()() { |
589 | 600 | CHECK_MESSAGE( tbb::this_task_arena::current_thread_index()==my_slot_at_construction, |
590 | 601 | "Current thread index has changed since the validator construction" ); |
| 602 | + check_slot_compatibility(my_slot_at_construction, my_arena); |
591 | 603 | } |
592 | 604 | }; |
593 | 605 |
|
@@ -2123,7 +2135,9 @@ TEST_CASE("Basic test of task_arena and task_group interoperability interface") |
2123 | 2135 | ta.enqueue([&] { |
2124 | 2136 | utils::ConcurrencyTracker ct; |
2125 | 2137 | barrier.wait(); |
2126 | | - per_thread_array[tbb::this_task_arena::current_thread_index() % num_threads]++; |
| 2138 | + int thread_idx = tbb::this_task_arena::current_thread_index(); |
| 2139 | + check_slot_compatibility(thread_idx, ta); |
| 2140 | + per_thread_array[thread_idx % num_threads]++; |
2127 | 2141 | }, tg); |
2128 | 2142 | }); |
2129 | 2143 |
|
|
0 commit comments