[PATCH] D53968: [LLD]fix windows mingw build with 'LLVM_LINK_LLVM_DYLIB' the lld will hang when exiting

Peiyuan Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 31 23:37:54 PDT 2018


SquallATF created this revision.
Herald added subscribers: llvm-commits, kristina.

Windows mingw shared build LLVM the work threads will exit before `static ThreadPoolExecutor exec` object's destructor run. Then the `Done.dec()` function will not be executed, lld will hang at `Latch` destructor. So need to use `llvm::ManagedStatic` wrap it to protect work threads safe exit when call `llvm_shutdown()`.


Repository:
  rL LLVM

https://reviews.llvm.org/D53968

Files:
  lib/Support/Parallel.cpp


Index: lib/Support/Parallel.cpp
===================================================================
--- lib/Support/Parallel.cpp
+++ lib/Support/Parallel.cpp
@@ -12,6 +12,7 @@
 
 #if LLVM_ENABLE_THREADS
 
+#include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Threading.h"
 
 #include <atomic>
@@ -28,7 +29,7 @@
   virtual ~Executor() = default;
   virtual void add(std::function<void()> func) = 0;
 
-  static Executor *getDefaultExecutor();
+  static Executor &getDefaultExecutor();
 };
 
 #if defined(_MSC_VER)
@@ -53,9 +54,9 @@
   }
 };
 
-Executor *Executor::getDefaultExecutor() {
-  static ConcRTExecutor exec;
-  return &exec;
+Executor &Executor::getDefaultExecutor() {
+  static llvm::ManagedStatic<ConcRTExecutor> exec;
+  return *exec;
 }
 
 #else
@@ -112,16 +113,16 @@
   parallel::detail::Latch Done;
 };
 
-Executor *Executor::getDefaultExecutor() {
-  static ThreadPoolExecutor exec;
-  return &exec;
+Executor &Executor::getDefaultExecutor() {
+  static llvm::ManagedStatic<ThreadPoolExecutor> exec;
+  return *exec;
 }
 #endif
 }
 
 void parallel::detail::TaskGroup::spawn(std::function<void()> F) {
   L.inc();
-  Executor::getDefaultExecutor()->add([&, F] {
+  Executor::getDefaultExecutor().add([&, F] {
     F();
     L.dec();
   });


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53968.172091.patch
Type: text/x-patch
Size: 1266 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181101/dca96ce3/attachment.bin>


More information about the llvm-commits mailing list