2025-01-18 17:39:25 +01:00
|
|
|
|
2025-01-18 00:44:20 +01:00
|
|
|
// Copyright Catch2 Authors
|
|
|
|
// Distributed under the Boost Software License, Version 1.0.
|
|
|
|
// (See accompanying file LICENSE.txt or copy at
|
|
|
|
// https://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
|
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
|
|
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include <catch2/internal/catch_textflow.hpp>
|
|
|
|
#include <catch2/benchmark/catch_benchmark.hpp>
|
|
|
|
|
|
|
|
#include <thread>
|
2025-01-18 18:29:04 +01:00
|
|
|
#include <atomic>
|
2025-01-18 00:44:20 +01:00
|
|
|
|
|
|
|
TEST_CASE( "ThreadAssertionTest",
|
|
|
|
"[Multithreading]" ) {
|
2025-01-18 18:29:04 +01:00
|
|
|
std::atomic_bool should_stop = false;
|
2025-01-18 00:44:20 +01:00
|
|
|
SECTION( "Basic" ) {
|
2025-01-18 18:29:04 +01:00
|
|
|
std::thread a([&should_stop] () {
|
|
|
|
while (!should_stop) {
|
2025-01-18 00:44:20 +01:00
|
|
|
FAIL_CHECK(false);
|
|
|
|
CHECK(true);
|
|
|
|
}
|
|
|
|
});
|
2025-01-18 18:29:04 +01:00
|
|
|
std::thread b([&should_stop] () {
|
|
|
|
while (!should_stop) {
|
2025-01-18 00:44:20 +01:00
|
|
|
FAIL_CHECK(false);
|
|
|
|
CHECK(true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
std::this_thread::sleep_for( std::chrono::milliseconds( 1'000 ) );
|
2025-01-18 18:29:04 +01:00
|
|
|
should_stop = true;
|
|
|
|
a.join();
|
|
|
|
b.join();
|
2025-01-18 00:44:20 +01:00
|
|
|
}
|
|
|
|
}
|