Make assertions thread-safe

This commit is contained in:
Jeremy Rifkin
2025-01-17 17:44:20 -06:00
parent 914aeecfe2
commit 83cbfb953a
14 changed files with 172 additions and 29 deletions

View File

@@ -0,0 +1,3 @@
add_executable(benchmarks catch_benchmarks.cpp)
target_link_libraries(benchmarks PRIVATE Catch2WithMain)
target_compile_features(benchmarks PUBLIC cxx_std_17)

View File

@@ -0,0 +1,25 @@
#include <catch2/catch_test_macros.hpp>
#include <catch2/benchmark/catch_benchmark.hpp>
#include <mutex>
std::recursive_mutex global_lock;
int no_lock() {
return 2;
}
int take_lock() {
std::unique_lock<std::recursive_mutex> lock(global_lock);
return 2;
}
TEST_CASE("std::recursive_mutex overhead benchmark", "[benchmark][mutex]") {
BENCHMARK("no lock") {
return no_lock();
};
BENCHMARK("with std::recursive_mutex") {
return take_lock();
};
}