[lld] [llvm] [Support] Support nested parallel TaskGroup via work-stealing (PR #189293)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 30 20:47:58 PDT 2026
================
@@ -205,33 +226,32 @@ size_t parallel::getThreadCount() {
}
#endif
-// Latch::sync() called by the dtor may cause one thread to block. If is a dead
-// lock if all threads in the default executor are blocked. To prevent the dead
-// lock, only allow the root TaskGroup to run tasks parallelly. In the scenario
-// of nested parallel_for_each(), only the outermost one runs parallelly.
+// Nested TaskGroups on worker threads use helpSync() which executes tasks from
+// the queue while waiting, preventing deadlock while enabling nested
+// parallelism.
TaskGroup::TaskGroup()
: Parallel(
#if LLVM_ENABLE_THREADS
- strategy.ThreadsRequested != 1 && threadIndex == UINT_MAX
+ strategy.ThreadsRequested != 1
#else
false
#endif
) {
}
TaskGroup::~TaskGroup() {
- // We must ensure that all the workloads have finished before decrementing the
- // instances count.
+#if LLVM_ENABLE_THREADS
+ // In a nested TaskGroup (threadIndex != -1u), actively help drain the queue.
+ if (Parallel && threadIndex != UINT_MAX)
----------------
MaskRay wrote:
Thanks for the suggestion. Added `isNested`
https://github.com/llvm/llvm-project/pull/189293
More information about the llvm-commits
mailing list