Skip to content

Commit b9553a9

Browse files
authored
Fix race condition in multi_threaded_observable_map test (#1550)
* Fix race condition in multi_threaded_observable_map test * Hook the other iterator movement methods.
1 parent 481f8f4 commit b9553a9

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

test/test/multi_threaded_common.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ namespace concurrent_collections
4545
// for the first time on the background thread.
4646
enum class collection_action
4747
{
48-
none, push_back, insert, erase, at, lookup
48+
none, push_back, insert, erase, at, lookup, advance
4949
};
5050

5151
// All of our concurrency tests consists of starting an
@@ -165,36 +165,46 @@ namespace concurrent_collections
165165
return owner->dereference_iterator(inner());
166166
}
167167

168-
// inherited: pointer operator->() const;
168+
pointer operator->() const
169+
{
170+
auto guard = owner->lock_const();
171+
owner->call_hook(collection_action::at);
172+
return iterator::operator->();
173+
}
169174

170175
concurrency_checked_random_access_iterator& operator++()
171176
{
177+
owner->call_hook(collection_action::advance);
172178
++inner();
173179
return *this;
174180
}
175181

176182
concurrency_checked_random_access_iterator& operator++(int)
177183
{
184+
owner->call_hook(collection_action::advance);
178185
auto prev = *this;
179186
++inner();
180187
return prev;
181188
}
182189

183190
concurrency_checked_random_access_iterator& operator--()
184191
{
192+
owner->call_hook(collection_action::advance);
185193
--inner();
186194
return *this;
187195
}
188196

189197
concurrency_checked_random_access_iterator& operator--(int)
190198
{
199+
owner->call_hook(collection_action::advance);
191200
auto prev = *this;
192201
--inner();
193202
return prev;
194203
}
195204

196205
concurrency_checked_random_access_iterator& operator+=(difference_type offset)
197206
{
207+
owner->call_hook(collection_action::advance);
198208
inner() += offset;
199209
return *this;
200210
}
@@ -206,6 +216,7 @@ namespace concurrent_collections
206216

207217
concurrency_checked_random_access_iterator& operator-=(difference_type offset)
208218
{
219+
owner->call_hook(collection_action::advance);
209220
inner() -= offset;
210221
return *this;
211222
}

test/test/multi_threaded_map.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ namespace
237237
{
238238
// MoveNext vs Remove
239239
bool moved = false;
240-
race(collection_action::at, [&]
240+
race(collection_action::advance, [&]
241241
{
242242
try
243243
{
@@ -273,7 +273,7 @@ namespace
273273
{
274274
// MoveNext vs Insert
275275
bool moved = false;
276-
race(collection_action::at, [&]
276+
race(collection_action::advance, [&]
277277
{
278278
try
279279
{

0 commit comments

Comments
 (0)