[ORC] Join materialization thread in unit test
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 23 Mar 2018 10:14:19 +0000 (10:14 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 23 Mar 2018 10:14:19 +0000 (10:14 +0000)
There's are race between this thread and the destructor of the test ORC
components on the main threads. I saw flaky failures there in about 4%
of the runs of this unit test.

llvm-svn: 328300

llvm/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp

index d37596ec5df3dc12aa0f23f4b8d34b05f295ddac..f862119c16595cb34a4b2ba84723edd487cc7ac8 100644 (file)
@@ -392,15 +392,15 @@ TEST(CoreAPIsTest, TestLookupWithThreadedMaterialization) {
 
   ExecutionSession ES(SSP);
 
-  auto MaterializeOnNewThread = [&ES](VSO &V,
-                                      std::unique_ptr<MaterializationUnit> MU) {
+  std::thread MaterializationThread;
+  auto MaterializeOnNewThread = [&](VSO &V,
+                                    std::unique_ptr<MaterializationUnit> MU) {
     // FIXME: Use move capture once we move to C++14.
     std::shared_ptr<MaterializationUnit> SharedMU = std::move(MU);
-    std::thread([&ES, &V, SharedMU]() {
+    MaterializationThread = std::thread([&ES, &V, SharedMU]() {
       if (auto Err = SharedMU->materialize(V))
         ES.reportError(std::move(Err));
-    })
-        .detach();
+    });
   };
 
   auto FooLookupResult =
@@ -410,6 +410,7 @@ TEST(CoreAPIsTest, TestLookupWithThreadedMaterialization) {
       << "lookup returned an incorrect address";
   EXPECT_EQ(FooLookupResult.getFlags(), FooSym.getFlags())
       << "lookup returned incorrect flags";
+  MaterializationThread.join();
 #endif
 }