[PATCH] D109914: [Support] Attempt to fix deadlock in ThreadGroup
Alexandre Ganea via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 18 10:49:28 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7b25fa8c7a15: [Support] Attempt to fix deadlock in ThreadGroup (authored by aganea).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D109914/new/
https://reviews.llvm.org/D109914
Files:
llvm/include/llvm/Support/Parallel.h
llvm/lib/Support/Parallel.cpp
Index: llvm/lib/Support/Parallel.cpp
===================================================================
--- llvm/lib/Support/Parallel.cpp
+++ llvm/lib/Support/Parallel.cpp
@@ -151,7 +151,12 @@
// 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<void()> F) {
if (Parallel) {
Index: llvm/include/llvm/Support/Parallel.h
===================================================================
--- llvm/include/llvm/Support/Parallel.h
+++ llvm/include/llvm/Support/Parallel.h
@@ -40,7 +40,10 @@
public:
explicit Latch(uint32_t Count = 0) : Count(Count) {}
- ~Latch() { sync(); }
+ ~Latch() {
+ // Ensure at least that sync() was called.
+ assert(Count == 0);
+ }
void inc() {
std::lock_guard<std::mutex> lock(Mutex);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109914.373424.patch
Type: text/x-patch
Size: 1171 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210918/1be86a7d/attachment.bin>
More information about the llvm-commits
mailing list