HigherOrderCO / HVM

A massively parallel, optimal functional runtime in Rust

Home Page:https://higherorderco.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Race condition in `VisitQueue::pop`

Boscop opened this issue · comments

commented

If 2 (or more) threads call pop at the same time and last > 0, they both find that last > 0 and both decrement last, then last underflows, (and then it does unsafe { self.data.get_unchecked(last - 1) } with that value):

let last = self.last.load(Ordering::Relaxed);
if last > 0 {
self.last.fetch_sub(1, Ordering::Relaxed);
self.init.fetch_min(last - 1, Ordering::Relaxed);
let visit = unsafe { self.data.get_unchecked(last - 1) }.swap(0, Ordering::Relaxed);