[PATCH] D78832: [Support] Fix fragile ThreadPool test
Alexandre Ganea via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 25 12:12:14 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG72b6fcbe781b: [Support] Fix fragile ThreadPool test (authored by aganea).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D78832/new/
https://reviews.llvm.org/D78832
Files:
llvm/unittests/Support/ThreadPool.cpp
Index: llvm/unittests/Support/ThreadPool.cpp
===================================================================
--- llvm/unittests/Support/ThreadPool.cpp
+++ llvm/unittests/Support/ThreadPool.cpp
@@ -71,7 +71,7 @@
void SetUp() override { MainThreadReady = false; }
- void TestAllThreads(ThreadPoolStrategy S);
+ void RunOnAllSockets(ThreadPoolStrategy S);
std::condition_variable WaitMainThread;
std::mutex WaitMainThreadMutex;
@@ -169,7 +169,7 @@
#if LLVM_ENABLE_THREADS == 1
-void ThreadPoolTest::TestAllThreads(ThreadPoolStrategy S) {
+void ThreadPoolTest::RunOnAllSockets(ThreadPoolStrategy S) {
// FIXME: Skip these tests on non-Windows because multi-socket system were not
// tested on Unix yet, and llvm::get_thread_affinity_mask() isn't implemented
// for Unix.
@@ -180,9 +180,18 @@
llvm::DenseSet<llvm::BitVector> ThreadsUsed;
std::mutex Lock;
{
+ std::condition_variable AllThreads;
+ std::mutex AllThreadsLock;
+ unsigned Active = 0;
+
ThreadPool Pool(S);
- for (size_t I = 0; I < 10000; ++I) {
+ for (size_t I = 0; I < S.compute_thread_count(); ++I) {
Pool.async([&] {
+ {
+ std::lock_guard<std::mutex> Guard(AllThreadsLock);
+ ++Active;
+ AllThreads.notify_one();
+ }
waitForMainThread();
std::lock_guard<std::mutex> Guard(Lock);
auto Mask = llvm::get_thread_affinity_mask();
@@ -190,6 +199,11 @@
});
}
ASSERT_EQ(true, ThreadsUsed.empty());
+ {
+ std::unique_lock<std::mutex> Guard(AllThreadsLock);
+ AllThreads.wait(Guard,
+ [&]() { return Active == S.compute_thread_count(); });
+ }
setMainThreadReady();
}
ASSERT_EQ(llvm::get_cpus(), ThreadsUsed.size());
@@ -197,12 +211,12 @@
TEST_F(ThreadPoolTest, AllThreads_UseAllRessources) {
CHECK_UNSUPPORTED();
- TestAllThreads({});
+ RunOnAllSockets({});
}
TEST_F(ThreadPoolTest, AllThreads_OneThreadPerCore) {
CHECK_UNSUPPORTED();
- TestAllThreads(llvm::heavyweight_hardware_concurrency());
+ RunOnAllSockets(llvm::heavyweight_hardware_concurrency());
}
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78832.260132.patch
Type: text/x-patch
Size: 2142 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200425/01d6fd7b/attachment.bin>
More information about the llvm-commits
mailing list