Skip to content

Commit

Permalink
fixed hand over hand locking
Browse files Browse the repository at this point in the history
  • Loading branch information
Hao-Wei committed Feb 11, 2024
1 parent dd0f290 commit 648b0d9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions benchmarks/concurrentKNN/octTree/flock/spin_lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ struct lock {
lock_entry newl = current.take_lock();
if (lck.compare_exchange_strong(current, newl)) {
RT result = f();
if (no_release == nullptr)
lck = newl.release_lock(); // release lock
else *no_release = true;
if (no_release == nullptr)
lck.compare_exchange_strong(newl, newl.release_lock());
// lck = newl.release_lock(); // release lock
else *no_release = true;
return std::optional<RT>(result);
} else {
return std::optional<RT>(); // fail
Expand Down Expand Up @@ -117,7 +118,7 @@ struct lock {
for (volatile int i=0; i < delay; i++);
delay = std::min(2*delay, max_delay);
if (cnt++ > 1000000)
std::cout << "in loop: " << this << std::endl;
std::cout << "in loop: " << this << std::endl;
}
}

Expand Down

0 comments on commit 648b0d9

Please sign in to comment.