diff options
author | akhropov <akhropov@yandex-team.com> | 2025-04-07 00:22:12 +0300 |
---|---|---|
committer | akhropov <akhropov@yandex-team.com> | 2025-04-07 00:34:38 +0300 |
commit | 28a80e63c3c727d8309a041bde8da045b41f4fda (patch) | |
tree | 902679f0bc5292a280ed84c36baf7da23f06b92d /library/cpp/threading/local_executor/tbb_local_executor.cpp | |
parent | f7d173e358dad9bac25d8d2353569ba66e5ad500 (diff) | |
download | ydb-28a80e63c3c727d8309a041bde8da045b41f4fda.tar.gz |
Fix TTbbLocalExecutor::GetWorkerThreadId. Enable test_fit_on_scipy_sparse_spmatrix on Windows.
commit_hash:c52cdc5529aff5cda1cbd11be2852647736ceb49
Diffstat (limited to 'library/cpp/threading/local_executor/tbb_local_executor.cpp')
-rw-r--r-- | library/cpp/threading/local_executor/tbb_local_executor.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/library/cpp/threading/local_executor/tbb_local_executor.cpp b/library/cpp/threading/local_executor/tbb_local_executor.cpp index 65d66594438..91a8460b0eb 100644 --- a/library/cpp/threading/local_executor/tbb_local_executor.cpp +++ b/library/cpp/threading/local_executor/tbb_local_executor.cpp @@ -14,9 +14,21 @@ int NPar::TTbbLocalExecutor<RespectTls>::GetThreadCount() const noexcept { template <bool RespectTls> int NPar::TTbbLocalExecutor<RespectTls>::GetWorkerThreadId() const noexcept { - return TbbArena.execute([] { - return tbb::this_task_arena::current_thread_index(); - }); + static thread_local int WorkerThreadId = -1; + if (WorkerThreadId == -1) { + // Can't rely on return value except checking that it is 'not_initialized' because of + // "Since a thread may exit the arena at any time if it does not execute a task, the index of + // a thread may change between any two tasks" + // (https://oneapi-spec.uxlfoundation.org/specifications/oneapi/latest/elements/onetbb/source/task_scheduler/task_arena/this_task_arena_ns#_CPPv4N3tbb15this_task_arena20current_thread_indexEv) + const auto tbbThreadIndex = tbb::this_task_arena::current_thread_index(); + if (tbbThreadIndex == tbb::task_arena::not_initialized) { + // This thread does not belong to TBB worker threads + WorkerThreadId = 0; + } else { + WorkerThreadId = ++RegisteredThreadCounter; + } + } + return WorkerThreadId; } template <bool RespectTls> |