[ORC] Add more synchronization to TestLookupWithUnthreadedMaterialization.
authorLang Hames <lhames@gmail.com>
Sat, 22 May 2021 14:55:12 +0000 (07:55 -0700)
committerLang Hames <lhames@gmail.com>
Sat, 22 May 2021 14:59:24 +0000 (07:59 -0700)
Don't run tasks until their corresponding thread has been added to the running
threads vector. This is an extention to fda4300da82, which doesn't seem to have
been enough to fix the synchronization issues on its own.

llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp

index 0dbbcb6..717987d 100644 (file)
@@ -1252,9 +1252,14 @@ TEST_F(CoreAPIsStandardTest, TestLookupWithThreadedMaterialization) {
   std::mutex WorkThreadsMutex;
   std::vector<std::thread> WorkThreads;
   ES.setDispatchTask([&](std::unique_ptr<Task> T) {
+    std::promise<void> WaitP;
     std::lock_guard<std::mutex> Lock(WorkThreadsMutex);
     WorkThreads.push_back(
-        std::thread([T = std::move(T)]() mutable { T->run(); }));
+        std::thread([T = std::move(T), WaitF = WaitP.get_future()]() mutable {
+          WaitF.get();
+          T->run();
+        }));
+    WaitP.set_value();
   });
 
   cantFail(JD.define(absoluteSymbols({{Foo, FooSym}})));