From 20caba75ebb4b5c60a204001d73be4485397b317 Mon Sep 17 00:00:00 2001 From: Ryan Shepherd Date: Wed, 18 Mar 2026 17:17:28 -0700 Subject: [PATCH 1/2] Fix race condition in multi_threaded_observable_map test --- test/test/multi_threaded_common.h | 10 ++++++++-- test/test/multi_threaded_map.cpp | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/test/test/multi_threaded_common.h b/test/test/multi_threaded_common.h index 026cb3264..7a12b5ece 100644 --- a/test/test/multi_threaded_common.h +++ b/test/test/multi_threaded_common.h @@ -45,7 +45,7 @@ namespace concurrent_collections // for the first time on the background thread. enum class collection_action { - none, push_back, insert, erase, at, lookup + none, push_back, insert, erase, at, lookup, advance }; // All of our concurrency tests consists of starting an @@ -165,10 +165,16 @@ namespace concurrent_collections return owner->dereference_iterator(inner()); } - // inherited: pointer operator->() const; + pointer operator->() const + { + auto guard = owner->lock_const(); + owner->call_hook(collection_action::at); + return iterator::operator->(); + } concurrency_checked_random_access_iterator& operator++() { + owner->call_hook(collection_action::advance); ++inner(); return *this; } diff --git a/test/test/multi_threaded_map.cpp b/test/test/multi_threaded_map.cpp index d0f68c1e2..ffa9988ba 100644 --- a/test/test/multi_threaded_map.cpp +++ b/test/test/multi_threaded_map.cpp @@ -237,7 +237,7 @@ namespace { // MoveNext vs Remove bool moved = false; - race(collection_action::at, [&] + race(collection_action::advance, [&] { try { @@ -273,7 +273,7 @@ namespace { // MoveNext vs Insert bool moved = false; - race(collection_action::at, [&] + race(collection_action::advance, [&] { try { From c1857bd73c673d2ad6762d2ce04e2083294b9576 Mon Sep 17 00:00:00 2001 From: Ryan Shepherd Date: Wed, 18 Mar 2026 17:39:04 -0700 Subject: [PATCH 2/2] Hook the other iterator movement methods. --- test/test/multi_threaded_common.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/test/multi_threaded_common.h b/test/test/multi_threaded_common.h index 7a12b5ece..3ed687743 100644 --- a/test/test/multi_threaded_common.h +++ b/test/test/multi_threaded_common.h @@ -181,6 +181,7 @@ namespace concurrent_collections concurrency_checked_random_access_iterator& operator++(int) { + owner->call_hook(collection_action::advance); auto prev = *this; ++inner(); return prev; @@ -188,12 +189,14 @@ namespace concurrent_collections concurrency_checked_random_access_iterator& operator--() { + owner->call_hook(collection_action::advance); --inner(); return *this; } concurrency_checked_random_access_iterator& operator--(int) { + owner->call_hook(collection_action::advance); auto prev = *this; --inner(); return prev; @@ -201,6 +204,7 @@ namespace concurrent_collections concurrency_checked_random_access_iterator& operator+=(difference_type offset) { + owner->call_hook(collection_action::advance); inner() += offset; return *this; } @@ -212,6 +216,7 @@ namespace concurrent_collections concurrency_checked_random_access_iterator& operator-=(difference_type offset) { + owner->call_hook(collection_action::advance); inner() -= offset; return *this; }