From f1cb615f4e4f480ef677757d6a8ef38ed79e9479 Mon Sep 17 00:00:00 2001 From: Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> Date: Sat, 18 Jan 2025 11:29:04 -0600 Subject: [PATCH] Rewrite multithreading test to not use jthreads --- tests/ExtraTests/CMakeLists.txt | 2 +- tests/ExtraTests/X37-Multithreading.cpp | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/ExtraTests/CMakeLists.txt b/tests/ExtraTests/CMakeLists.txt index da2ba6bc..52d1f0f8 100644 --- a/tests/ExtraTests/CMakeLists.txt +++ b/tests/ExtraTests/CMakeLists.txt @@ -481,7 +481,7 @@ set_tests_properties( add_executable(Multithreading ${TESTS_DIR}/X37-Multithreading.cpp) target_link_libraries(Multithreading PRIVATE Catch2::Catch2WithMain) -target_compile_features(Multithreading PRIVATE cxx_std_20) +target_compile_features(Multithreading PRIVATE cxx_std_11) add_test( NAME Reporters::Multithreading COMMAND ${CMAKE_COMMAND} -E env $ diff --git a/tests/ExtraTests/X37-Multithreading.cpp b/tests/ExtraTests/X37-Multithreading.cpp index e84f2bf1..953e8c30 100644 --- a/tests/ExtraTests/X37-Multithreading.cpp +++ b/tests/ExtraTests/X37-Multithreading.cpp @@ -11,25 +11,27 @@ #include #include -#include +#include TEST_CASE( "ThreadAssertionTest", "[Multithreading]" ) { + std::atomic_bool should_stop = false; SECTION( "Basic" ) { - std::jthread a([] (const std::stop_token& token) { - while (!token.stop_requested()) { + std::thread a([&should_stop] () { + while (!should_stop) { FAIL_CHECK(false); CHECK(true); } }); - std::jthread b([] (const std::stop_token& token) { - while (!token.stop_requested()) { + std::thread b([&should_stop] () { + while (!should_stop) { FAIL_CHECK(false); CHECK(true); } }); std::this_thread::sleep_for( std::chrono::milliseconds( 1'000 ) ); - a.get_stop_source().request_stop(); - b.get_stop_source().request_stop(); + should_stop = true; + a.join(); + b.join(); } }