From 6ec49c0ba81efea26fbe2eabe3bd6e88e97d2dfc Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 23 Mar 2018 10:14:19 +0000 Subject: [PATCH] [ORC] Join materialization thread in unit test 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 --- unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp b/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp index d37596ec5df..f862119c165 100644 --- a/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp +++ b/unittests/ExecutionEngine/Orc/CoreAPIsTest.cpp @@ -392,15 +392,15 @@ TEST(CoreAPIsTest, TestLookupWithThreadedMaterialization) { ExecutionSession ES(SSP); - auto MaterializeOnNewThread = [&ES](VSO &V, - std::unique_ptr MU) { + std::thread MaterializationThread; + auto MaterializeOnNewThread = [&](VSO &V, + std::unique_ptr MU) { // FIXME: Use move capture once we move to C++14. std::shared_ptr 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 }