Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit db5da1b

Browse files
author
Szymon Romik
authored
Merge pull request #898 from igchor/spurious_wakepup_fix_1.9
tests: fix parallel_exec_with sync implementation
2 parents 2748537 + e21c502 commit db5da1b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tests/common/thread_helpers.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,19 @@ parallel_exec_with_sync(size_t concurrency, Function f)
6363
{
6464
std::condition_variable cv;
6565
std::mutex m;
66-
size_t counter = 0;
66+
std::unique_ptr<size_t> counter =
67+
std::unique_ptr<size_t>(new size_t(0));
6768

6869
parallel_exec(concurrency, [&](size_t tid) {
6970
f(tid);
7071

7172
{
7273
std::unique_lock<std::mutex> lock(m);
73-
counter++;
74-
if (counter < concurrency)
75-
cv.wait(lock);
74+
(*counter)++;
75+
if (*counter < concurrency)
76+
cv.wait(lock, [&] {
77+
return *counter >= concurrency;
78+
});
7679
else
7780
/*
7881
* notify_call could be called outside of a lock

0 commit comments

Comments
 (0)