[llvm] [Parallel] Ensure getThreadIndex()==0 for sequential tasks (PR #109084)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 19 13:36:42 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;
----------------
MaskRay wrote:
This patch is an almost revert of reviews.llvm.org/D148728 .
Since the use case is so special, I'm fine with the style suggested by @aganea (also the initial style I used for parallel relocation scanning):
```cpp
if (serial)
fn();
else
tg.spawn(fn);
}
};
if (serial)
tg.spawn(outerFn);
else
outerFn();
```
Perhaps Parallel.cpp could add `setThreadIndex` and lld/ELF/Relocations.cpp could call `setThreadIndex(0)` to make the pattern more explicit. It's up to lld to ensure correctness.
https://github.com/llvm/llvm-project/pull/109084
More information about the llvm-commits
mailing list