[PATCH] D114363: [ThreadPool] Do not return shared futures.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 22 05:15:45 PST 2021
fhahn created this revision.
fhahn added reviewers: Meinersbur, dblaikie, mehdi_amini, rriddle.
Herald added a subscriber: dexonsmith.
fhahn requested review of this revision.
Herald added a project: LLVM.
The only users of returned futures from ThreadPool is llvm-reduce after
D113857 <https://reviews.llvm.org/D113857>.
There should be no cases where multiple threads wait on the same future,
so there should be no need to return std::shared_future<>. Instead return
plain std::future<>.
If users need to share a future between multiple threads, they can share
the futures themselves.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D114363
Files:
llvm/include/llvm/Support/ThreadPool.h
llvm/tools/llvm-reduce/deltas/Delta.cpp
Index: llvm/tools/llvm-reduce/deltas/Delta.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/Delta.cpp
+++ llvm/tools/llvm-reduce/deltas/Delta.cpp
@@ -267,7 +267,7 @@
WriteBitcodeToFile(*Test.getProgram().M, BCOS);
}
- std::deque<std::shared_future<SmallString<0>>> TaskQueue;
+ std::deque<std::future<SmallString<0>>> TaskQueue;
for (auto I = ChunksStillConsideredInteresting.rbegin(),
E = ChunksStillConsideredInteresting.rend();
I != E; ++I) {
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.388887.patch
Type: text/x-patch
Size: 2235 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211122/9f3715dd/attachment.bin>
More information about the llvm-commits
mailing list