[llvm] [Parallel] Ensure getThreadIndex()==0 for sequential tasks (PR #109084)
Alexey Lapshin via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 19 13:25:49 PDT 2024
================
@@ -217,13 +194,18 @@ TaskGroup::~TaskGroup() {
void TaskGroup::spawn(std::function<void()> F, bool Sequential) {
#if LLVM_ENABLE_THREADS
if (Parallel) {
+ if (Sequential) {
+ // Act as worker thread 0.
+ threadIndex = 0;
----------------
avl-llvm wrote:
If the threadIndex would be set to 0 then it might clash with another task which is already has threadIndex equal 0. In that cast the resource with index 0 would be accessed concurrently which is unwanted behavior.
if we will use old behavior:
`if (serial)
fn();
else
tg.execute(fn);
`
then we will have assertion checking that thread_index is not equal UINT_MAX. (thread_index is equal to UINT_MAX for main thread)
In my patch I use separate thread for sequential tasks. It looks like this solve the problem when thread_index equal UINT_MAX and when zero index clashes with another thread.
https://github.com/llvm/llvm-project/pull/109084
More information about the llvm-commits
mailing list