Skip to content

Commit

Permalink
Avoid compare_exhange_weak in linear_page.rs
Browse files Browse the repository at this point in the history
compare_exchange_weak can fail spuriously (ie, even if the values match) on some platforms (in my case arm musl).
This leads to a panic as we are assuming that x is not null, but in fact it can be null in the spurious failure case.
We can wrap this in a loop and check for this, or we can just use the strong variant as I have here, and let llvm do the loop for us.
  • Loading branch information
jackkleeman authored and EVaillant committed Jan 24, 2024
1 parent 3d9ed18 commit e151717
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/linear_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<T> LinearPage<T> {
let new = Box::into_raw(Box::new(LinearPage::<T>::new(init)));
match self
.next
.compare_exchange_weak(current, new, Ordering::SeqCst, Ordering::Relaxed)
.compare_exchange(current, new, Ordering::SeqCst, Ordering::Relaxed)
{
Ok(_) => {
current = new;
Expand Down

0 comments on commit e151717

Please sign in to comment.