hint_core_should_pause -

# `hint_core_should_pause`

The tracking issue for this feature is: #41196

Many programs have spin loops like the following:

    # #![allow(unused_variables)]
    #fn main() {
    use std::sync::atomic::{AtomicBool,Ordering};

    fn spin_loop(value: &AtomicBool) {
        loop {
            if value.load(Ordering::Acquire) {
                 break;
            }
        }
    }

    #}

These programs can be improved in performance like so:

    # #![allow(unused_variables)]
    #![feature(hint_core_should_pause)]
    #fn main() {
    use std::sync::atomic;
    use std::sync::atomic::{AtomicBool,Ordering};

    fn spin_loop(value: &AtomicBool) {
        loop {
            if value.load(Ordering::Acquire) {
                 break;
            }
            atomic::hint_core_should_pause();
        }
    }

    #}

Further improvements could combine `hint_core_should_pause` with exponential backoff or `std::thread::yield_now`.