You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect example in documentation for std::hint::spin_loop #80644
#![allow(unused)]fnmain(){fn_inner() -> Result<(),impl core::fmt::Debug>{use std::sync::atomic::{AtomicBool,Ordering};use std::sync::Arc;use std::{hint, thread};// A shared atomic value that threads will use to coordinatelet live = Arc::new(AtomicBool::new(false));// In a background thread we'll eventually set the valuelet bg_work = {let live = live.clone();
thread::spawn(move || {// Do some work, then make the value livedo_some_work();
live.store(true,Ordering::Release);})};// Back on our current thread, we wait for the value to be setwhile live.load(Ordering::Acquire){// The spin loop is a hint to the CPU that we're waiting, but probably// not for very long
hint::spin_loop();}// The value is now setfndo_some_work(){}do_some_work();
bg_work.join()?;Ok::<(),Box<dyn core::any::Any + Send + 'static>>(())}_inner().unwrap()}
I think that the values for AtomicBool might be inverted, because this program never terminates when run in the playground. Should this be fixed or is there something I'm missing?
Activity
jyn514 commentedon Jan 3, 2021
@booleancoercion good catch, thanks! Would you like to fix it yourself? There are instructions at https://rustc-dev-guide.rust-lang.org/getting-started.html; the command to test your changes is
x.py test --stage 0 --doc library/std.booleancoercion commentedon Jan 3, 2021
@jyn514 I'd love to! Do I just make a PR that references this issue then?
jyn514 commentedon Jan 3, 2021
@booleancoercion yup, that would be great :)
Rollup merge of rust-lang#80656 - booleancoercion:master, r=sfackler