pub fn unpark_all(addr: *const ())
Expand description

Wakes all threads parked on addr.

Should be called after making the expected of the corresponding parks return false.

Notes

  • The memory pointed to by addr isn’t written to, it isn’t read and no references to it are formed.
  • If no thread is waiting on addr, no thread is woken, but it still requires locking, so it’s not recommended to call it without reason.
  • This function ensures that if it is called after an effect, that would cause the expected of a call to park with the same addr, park will either be woken, or it will not have gone to sleep and will return.

Example

use core::sync::atomic::AtomicUsize;
use core::sync::atomic::Ordering::{AcqRel, Acquire};

use sparking_lot_core::{park, unpark_all};

struct Latch(AtomicUsize);

impl Latch {
    fn new(num_threads: usize) -> Self {
        Self(AtomicUsize::new(num_threads))
    }

    fn wait(&self) {
        if self.0.fetch_sub(1, AcqRel) == 1 {
            unpark_all(self as *const _ as *const _);
        }
        else {
            /* SAFETY:
             * - no calls to sparking_lot_core funtions in closure
             * - owned address
             */
            unsafe {
                park(self as *const _ as *const _, || self.0.load(Acquire) != 0);   
            }
        }
    }
}