[PATCH] D114363: [ThreadPool] Do not return shared futures.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 23 00:12:36 PST 2021


fhahn updated this revision to Diff 389102.
fhahn added a comment.
Herald added subscribers: sdasgup3, wenzhicui, wrengr, Chia-hungDuan, dcaballe, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, stephenneuendorffer, liufengdb, aartbik, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen.
Herald added a project: MLIR.

Rebase so this can be landed independent of D113857 <https://reviews.llvm.org/D113857>.

It also updates the only place I could find that was storing futures in a container (in mlir/include/mlir/IR/Threading.h). The futures are only used by the main thread for waiting, so they shouldnt need to be shared.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D114363/new/

https://reviews.llvm.org/D114363

Files:
  llvm/include/llvm/Support/ThreadPool.h
  mlir/include/mlir/IR/Threading.h


Index: mlir/include/mlir/IR/Threading.h
===================================================================
--- mlir/include/mlir/IR/Threading.h
+++ mlir/include/mlir/IR/Threading.h
@@ -71,14 +71,14 @@
   // Otherwise, process the elements in parallel.
   llvm::ThreadPool &threadPool = context->getThreadPool();
   size_t numActions = std::min(numElements, threadPool.getThreadCount());
-  SmallVector<std::shared_future<void>> threadFutures;
+  SmallVector<std::future<void>> threadFutures;
   threadFutures.reserve(numActions - 1);
   for (unsigned i = 1; i < numActions; ++i)
     threadFutures.emplace_back(threadPool.async(processFn));
   processFn();
 
   // Wait for all of the threads to finish.
-  for (std::shared_future<void> &future : threadFutures)
+  for (std::future<void> &future : threadFutures)
     future.wait();
   return failure(processingFailed);
 }
Index: llvm/include/llvm/Support/ThreadPool.h
===================================================================
--- llvm/include/llvm/Support/ThreadPool.h
+++ llvm/include/llvm/Support/ThreadPool.h
@@ -56,8 +56,7 @@
 
   /// Asynchronous submission of a task to the pool. The returned future can be
   /// used to wait for the task to finish and is *non-blocking* on destruction.
-  template <typename Func>
-  auto async(Func &&F) -> std::shared_future<decltype(F())> {
+  template <typename Func> auto async(Func &&F) -> std::future<decltype(F())> {
     return asyncImpl(std::function<decltype(F())()>(std::forward<Func>(F)));
   }
 
@@ -101,7 +100,7 @@
   /// Asynchronous submission of a task to the pool. The returned future can be
   /// used to wait for the task to finish and is *non-blocking* on destruction.
   template <typename ResTy>
-  std::shared_future<ResTy> asyncImpl(std::function<ResTy()> Task) {
+  std::future<ResTy> asyncImpl(std::function<ResTy()> Task) {
 
 #if LLVM_ENABLE_THREADS
     /// Wrap the Task in a std::function<void()> that sets the result of the
@@ -117,12 +116,12 @@
       Tasks.push(std::move(R.first));
     }
     QueueCondition.notify_one();
-    return R.second.share();
+    return std::move(R.second);
 
 #else // LLVM_ENABLE_THREADS Disabled
 
     // Get a Future with launch::deferred execution using std::async
-    auto Future = std::async(std::launch::deferred, std::move(Task)).share();
+    auto Future = std::async(std::launch::deferred, std::move(Task));
     // Wrap the future so that both ThreadPool::wait() can operate and the
     // returned future can be sync'ed on.
     Tasks.push([Future]() { Future.get(); });


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114363.389102.patch
Type: text/x-patch
Size: 2556 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211123/30773f36/attachment.bin>


More information about the llvm-commits mailing list