[ORC] Fix race condtition in CoreAPIsTest.
authorLang Hames <lhames@gmail.com>
Sat, 22 May 2021 03:50:22 +0000 (20:50 -0700)
committerLang Hames <lhames@gmail.com>
Sat, 22 May 2021 04:11:54 +0000 (21:11 -0700)
This test has been failing intermittently on some builders, probably due to a
race on the WorkThreads vector. This patch should fix that.

llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp

index 8935ea4..0dbbcb6 100644 (file)
@@ -1249,8 +1249,10 @@ TEST_F(CoreAPIsStandardTest, TestLookupWithUnthreadedMaterialization) {
 TEST_F(CoreAPIsStandardTest, TestLookupWithThreadedMaterialization) {
 #if LLVM_ENABLE_THREADS
 
+  std::mutex WorkThreadsMutex;
   std::vector<std::thread> WorkThreads;
   ES.setDispatchTask([&](std::unique_ptr<Task> T) {
+    std::lock_guard<std::mutex> Lock(WorkThreadsMutex);
     WorkThreads.push_back(
         std::thread([T = std::move(T)]() mutable { T->run(); }));
   });