From c4bd2b43b293827b7ec880a10a6e491f0cc94211 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 20 Feb 2022 15:39:23 +0100 Subject: Vendor import of llvm-project branch release/13.x llvmorg-13.0.1-0-g75e33f71c2da. --- llvm/lib/Support/Parallel.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Support/Parallel.cpp') diff --git a/llvm/lib/Support/Parallel.cpp b/llvm/lib/Support/Parallel.cpp index 9a2e1003da5a..71e3a1362f7e 100644 --- a/llvm/lib/Support/Parallel.cpp +++ b/llvm/lib/Support/Parallel.cpp @@ -151,7 +151,12 @@ static std::atomic TaskGroupInstances; // lock, only allow the first TaskGroup to run tasks parallelly. In the scenario // of nested parallel_for_each(), only the outermost one runs parallelly. TaskGroup::TaskGroup() : Parallel(TaskGroupInstances++ == 0) {} -TaskGroup::~TaskGroup() { --TaskGroupInstances; } +TaskGroup::~TaskGroup() { + // We must ensure that all the workloads have finished before decrementing the + // instances count. + L.sync(); + --TaskGroupInstances; +} void TaskGroup::spawn(std::function F) { if (Parallel) { -- cgit v1.2.3