[llvm] [Parallel] Ensure getThreadIndex()==0 for sequential tasks (PR #109084)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 16:31:28 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:
I think this suggestion is what I previously did (see the deleted code on https://reviews.llvm.org/D148728)
```cpp
if (serial)
fn();
else
tg.execute(fn);
```
It seems convenient to have a Parallel helper function to simplify this pattern. I do agree that the load-bearing `spawn` should not have extra overhead (`bool Sequential = false`) but that is not the focus of this patch.
---
Perhaps the next patch can add:
```
spawn(std::function f)
execute(std::function f, bool serial)
```
https://github.com/llvm/llvm-project/pull/109084
More information about the llvm-commits
mailing list