Skip to content

Commit 5ce1cc8

Browse files
Use execution_slot to ensure backwards compatibility (#1853)
Co-authored-by: Aleksei Fedotov <[email protected]>
1 parent 3bb1c63 commit 5ce1cc8

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

include/oneapi/tbb/detail/_task.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ TBB_EXPORT void __TBB_EXPORTED_FUNC spawn(d1::task& t, d1::task_group_context& c
6060
TBB_EXPORT void __TBB_EXPORTED_FUNC execute_and_wait(d1::task& t, d1::task_group_context& t_ctx, d1::wait_context&, d1::task_group_context& w_ctx);
6161
TBB_EXPORT void __TBB_EXPORTED_FUNC wait(d1::wait_context&, d1::task_group_context& ctx);
6262
TBB_EXPORT d1::slot_id __TBB_EXPORTED_FUNC execution_slot(const d1::execution_data*);
63-
TBB_EXPORT d1::slot_id __TBB_EXPORTED_FUNC execution_slot(const d1::task_arena_base&);
6463
TBB_EXPORT d1::task_group_context* __TBB_EXPORTED_FUNC current_context();
6564
TBB_EXPORT d1::wait_tree_vertex_interface* get_thread_reference_vertex(d1::wait_tree_vertex_interface* wc);
6665
TBB_EXPORT d1::task* __TBB_EXPORTED_FUNC current_task_ptr();

include/oneapi/tbb/task_arena.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ TBB_EXPORT void __TBB_EXPORTED_FUNC submit(d1::task&, d1::task_group_context&, a
103103
TBB_EXPORT void __TBB_EXPORTED_FUNC enter_parallel_phase(d1::task_arena_base*, std::uintptr_t);
104104
TBB_EXPORT void __TBB_EXPORTED_FUNC exit_parallel_phase(d1::task_arena_base*, std::uintptr_t);
105105
#endif
106+
107+
// Maintained for backwards compatibility
108+
TBB_EXPORT d1::slot_id __TBB_EXPORTED_FUNC execution_slot(const d1::task_arena_base&);
106109
} // namespace r1
107110

108111
namespace d2 {

test/tbb/test_task_arena.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@
4848
//! \file test_task_arena.cpp
4949
//! \brief Test for [scheduler.task_arena scheduler.task_scheduler_observer] specification
5050

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+
5161
//--------------------------------------------------//
5262
// Test that task_arena::initialize and task_arena::terminate work when doing nothing else.
5363
/* maxthread is treated as the biggest possible concurrency level. */
@@ -449,6 +459,7 @@ class TestArenaConcurrencyBody : utils::NoAssign {
449459
// Arena's functor
450460
void operator()() const {
451461
int idx = tbb::this_task_arena::current_thread_index();
462+
check_slot_compatibility(idx, my_a);
452463
REQUIRE( idx < (my_max_concurrency > 1 ? my_max_concurrency : 2) );
453464
REQUIRE( my_a.max_concurrency() == tbb::this_task_arena::max_concurrency() );
454465
int max_arena_concurrency = tbb::this_task_arena::max_concurrency();
@@ -588,6 +599,7 @@ struct TaskArenaValidator {
588599
void operator()() {
589600
CHECK_MESSAGE( tbb::this_task_arena::current_thread_index()==my_slot_at_construction,
590601
"Current thread index has changed since the validator construction" );
602+
check_slot_compatibility(my_slot_at_construction, my_arena);
591603
}
592604
};
593605

@@ -2123,7 +2135,9 @@ TEST_CASE("Basic test of task_arena and task_group interoperability interface")
21232135
ta.enqueue([&] {
21242136
utils::ConcurrencyTracker ct;
21252137
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]++;
21272141
}, tg);
21282142
});
21292143

0 commit comments

Comments
 (0)