summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/ThreadPool.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/unittests/Support/ThreadPool.cpp')
-rw-r--r--llvm/unittests/Support/ThreadPool.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/unittests/Support/ThreadPool.cpp b/llvm/unittests/Support/ThreadPool.cpp
index 0da33ad50c0..d2d50c3764e 100644
--- a/llvm/unittests/Support/ThreadPool.cpp
+++ b/llvm/unittests/Support/ThreadPool.cpp
@@ -147,6 +147,25 @@ TEST_F(ThreadPoolTest, GetFuture) {
ASSERT_EQ(2, i.load());
}
+TEST_F(ThreadPoolTest, TaskWithResult) {
+ CHECK_UNSUPPORTED();
+ // By making only 1 thread in the pool the two tasks are serialized with
+ // respect to each other, which means that the second one must return 2.
+ ThreadPool Pool{1};
+ std::atomic_int i{0};
+ Pool.async([this, &i] {
+ waitForMainThread();
+ ++i;
+ });
+ // Force the future using get()
+ std::shared_future<int> Future = Pool.async([&i] { return ++i; });
+ ASSERT_EQ(0, i.load());
+ setMainThreadReady();
+ int Result = Future.get();
+ ASSERT_EQ(2, i.load());
+ ASSERT_EQ(2, Result);
+}
+
TEST_F(ThreadPoolTest, PoolDestruction) {
CHECK_UNSUPPORTED();
// Test that we are waiting on destruction
OpenPOWER on IntegriCloud