From 6b30ab54320f15c5080dcd946e9d33a56ed5e991 Mon Sep 17 00:00:00 2001 From: Ayrton Chilibeck Date: Sun, 8 Sep 2024 07:03:27 -0600 Subject: [PATCH] Naive multithreading support Simply spawns a thread for every toolchain. Note that this would probably brick a computer without a lot of cores or running tests with a whole bunch of packages. Implementation will need to limit the number of spawnable threads in the future. --- src/testharness/TestHarness.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/testharness/TestHarness.cpp b/src/testharness/TestHarness.cpp index 05ccebc..5eb30a7 100644 --- a/src/testharness/TestHarness.cpp +++ b/src/testharness/TestHarness.cpp @@ -20,16 +20,28 @@ void swap(TestResult& first, TestResult& second) { // Builds TestSet during object creation. bool TestHarness::runTests() { - bool failed = false; + std::vector threadPool; + + // Initialize the threads // Iterate over executables. for (auto exePair : cfg.getExecutables()) { // Iterate over toolchains. for (auto& tcPair : cfg.getToolChains()) { std::thread t(&TestHarness::threadRunTestsForToolChain, this, tcPair.first, exePair.first); + threadPool.push_back(std::move(t)); + } + } + + bool failed = false; + // Iterate over executables. + for (auto exePair : cfg.getExecutables()) { + // Iterate over toolchains. + for (auto& tcPair : cfg.getToolChains()) { if (aggregateTestResultsForToolChain(tcPair.first, exePair.first) == 1) failed = true; - t.join(); + threadPool.back().join(); + threadPool.pop_back(); } } return failed;