Skip to content

Commit 2b19329

Browse files
authored
Merge pull request #62 from geoffreyblake/fix_race
Fix race condition in synchronize_threads()
2 parents 0db2492 + ea87a07 commit 2b19329

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

benchmarks/lockhammer/include/atomics.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ void synchronize_threads(uint64_t *barrier, unsigned long nthrds)
494494
uint64_t tmp_sense = ~global_sense & SENSE_BIT_MASK;
495495
uint32_t local_sense = (uint32_t)(tmp_sense >> 32);
496496

497-
fetchadd64_acquire(barrier, 2);
498-
if (*barrier == ((nthrds * 2) | global_sense)) {
497+
uint64_t old_barrier = fetchadd64_acquire(barrier, 2);
498+
if (old_barrier == (((nthrds - 1) * 2) | global_sense)) {
499499
// Make sure the store gets observed by the system. Reset count
500500
// to zero and flip the sense bit.
501501
__atomic_store_n(barrier, tmp_sense, __ATOMIC_RELEASE);

0 commit comments

Comments
 (0)