Closed
Description
The following program loops forever in Miri, but terminates as expected with normal rustc:
use std::thread;
use std::sync::atomic::{AtomicUsize, Ordering};
static FLAG: AtomicUsize = AtomicUsize::new(0);
fn main() {
let j = thread::spawn(|| {
while FLAG.load(Ordering::Acquire) == 0 {
// spin and wait
}
});
thread::yield_now();
FLAG.store(1, Ordering::Release);
j.join().unwrap();
}
One could argue the spin loop should use hint::spin_loop();
, but that is unstable -- and it seems reasonable to expect the scheduler to de-schedule a thread at some point even if it does not yield.
Cc @vakaras