Skip to content

Commit 2ad60b3

Browse files
committed
fix: use atomic in BLS_Verify_BatchedParallel to avoid data race
1 parent 24ad076 commit 2ad60b3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/bench/bls.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <random.h>
88
#include <util/time.h>
99

10+
#include <atomic>
1011
#include <iostream>
1112

1213
static void BuildTestVectors(size_t count, size_t invalidCount,
@@ -314,9 +315,9 @@ static void BLS_Verify_BatchedParallel(benchmark::Bench& bench)
314315

315316
std::list<std::pair<size_t, std::future<bool>>> futures;
316317

317-
volatile bool cancel = false;
318-
auto cancelCond = [&]() {
319-
return cancel;
318+
std::atomic<bool> cancel{false};
319+
auto cancelCond = [&]() -> bool {
320+
return cancel.load();
320321
};
321322

322323
CBLSWorker blsWorker;
@@ -348,7 +349,7 @@ static void BLS_Verify_BatchedParallel(benchmark::Bench& bench)
348349
}
349350
});
350351

351-
cancel = true;
352+
cancel.store(true);
352353
while (blsWorker.IsAsyncVerifyInProgress())
353354
{
354355
UninterruptibleSleep(std::chrono::milliseconds{100});

0 commit comments

Comments
 (0)