[PATCH] D15464: Add a C++11 ThreadPool implementation in LLVM

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 14 15:56:12 PST 2015


tejohnson added a comment.

Here's the fix I mentioned on IRC:

diff --git a/include/llvm/Support/ThreadPool.h b/include/llvm/Support/ThreadPool.h
index c388c07..4b29392 100644

- a/include/llvm/Support/ThreadPool.h

+++ b/include/llvm/Support/ThreadPool.h
@@ -50,7 +50,7 @@ public:

  template <typename Function, typename... Args>
  inline std::shared_future<void> async(Function &&F, Args &&... ArgList) {
    auto Task =

- std::bind(std::forward<Function>(F), std::forward<Args...>(ArgList...));

+        std::bind(std::forward<Function>(F), std::forward<Args>(ArgList)...);

    return asyncImpl(Task);
  }
   

diff --git a/unittests/Support/ThreadPool.cpp b/unittests/Support/ThreadPool.cpp
index d36341e..5457cdc 100644

- a/unittests/Support/ThreadPool.cpp

+++ b/unittests/Support/ThreadPool.cpp
@@ -44,6 +44,20 @@ TEST(ThreadPoolTest, AsyncBarrier) {

  ASSERT_EQ(5, checked_in);

}

+static void TestFunc(std::atomic_int &checked_in, int i) { checked_in += i; }
+
+TEST(ThreadPoolTest, AsyncBarrierArgs) {
+  // Test that async works with a function requiring multiple parameters.
+  std::atomic_int checked_in{0};
+
+  ThreadPool Pool;
+  for (size_t i = 0; i < 5; ++i) {
+    Pool.async(TestFunc, std::ref(checked_in), i);
+  }
+  Pool.wait();
+  ASSERT_EQ(10, checked_in);
+}
+
 TEST(ThreadPoolTest, Async) {

  ThreadPool Pool;


http://reviews.llvm.org/D15464





More information about the llvm-commits mailing list