Update potential misunderstanding about thread safety
This commit is contained in:
@@ -402,21 +402,22 @@ TEST_CASE("thread safety") {
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("gauge multi-writer with CAS") {
|
||||
SUBCASE("gauge multi-writer contention") {
|
||||
auto gauge_family =
|
||||
metric::create_gauge("thread_test_gauge", "Thread test gauge");
|
||||
auto shared_gauge = gauge_family.create({{"shared", "true"}});
|
||||
|
||||
std::vector<std::thread> threads;
|
||||
std::latch start_latch{num_threads};
|
||||
|
||||
// Multiple threads writing to same gauge (uses atomic CAS)
|
||||
// Multiple threads create gauges with the same labels, writing to the same
|
||||
// underlying state, testing CAS contention.
|
||||
for (int i = 0; i < num_threads; ++i) {
|
||||
threads.emplace_back([&]() {
|
||||
auto gauge = gauge_family.create({{"shared", "true"}});
|
||||
start_latch.arrive_and_wait();
|
||||
|
||||
for (int j = 0; j < ops_per_thread; ++j) {
|
||||
shared_gauge.inc(1.0);
|
||||
gauge.inc(1.0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user