mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
sync: Barrier doc should use task, not thread (#3780)
This commit is contained in:
parent
9ff7d8c352
commit
d846bf24b1
@ -2,7 +2,7 @@ use crate::sync::watch;
|
||||
|
||||
use std::sync::Mutex;
|
||||
|
||||
/// A barrier enables multiple threads to synchronize the beginning of some computation.
|
||||
/// A barrier enables multiple tasks to synchronize the beginning of some computation.
|
||||
///
|
||||
/// ```
|
||||
/// # #[tokio::main]
|
||||
@ -52,10 +52,10 @@ struct BarrierState {
|
||||
}
|
||||
|
||||
impl Barrier {
|
||||
/// Creates a new barrier that can block a given number of threads.
|
||||
/// Creates a new barrier that can block a given number of tasks.
|
||||
///
|
||||
/// A barrier will block `n`-1 threads which call [`Barrier::wait`] and then wake up all
|
||||
/// threads at once when the `n`th thread calls `wait`.
|
||||
/// A barrier will block `n`-1 tasks which call [`Barrier::wait`] and then wake up all
|
||||
/// tasks at once when the `n`th task calls `wait`.
|
||||
pub fn new(mut n: usize) -> Barrier {
|
||||
let (waker, wait) = crate::sync::watch::channel(0);
|
||||
|
||||
@ -79,11 +79,11 @@ impl Barrier {
|
||||
|
||||
/// Does not resolve until all tasks have rendezvoused here.
|
||||
///
|
||||
/// Barriers are re-usable after all threads have rendezvoused once, and can
|
||||
/// Barriers are re-usable after all tasks have rendezvoused once, and can
|
||||
/// be used continuously.
|
||||
///
|
||||
/// A single (arbitrary) future will receive a [`BarrierWaitResult`] that returns `true` from
|
||||
/// [`BarrierWaitResult::is_leader`] when returning from this function, and all other threads
|
||||
/// [`BarrierWaitResult::is_leader`] when returning from this function, and all other tasks
|
||||
/// will receive a result that will return `false` from `is_leader`.
|
||||
pub async fn wait(&self) -> BarrierWaitResult {
|
||||
// NOTE: we are taking a _synchronous_ lock here.
|
||||
@ -129,14 +129,14 @@ impl Barrier {
|
||||
}
|
||||
}
|
||||
|
||||
/// A `BarrierWaitResult` is returned by `wait` when all threads in the `Barrier` have rendezvoused.
|
||||
/// A `BarrierWaitResult` is returned by `wait` when all tasks in the `Barrier` have rendezvoused.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BarrierWaitResult(bool);
|
||||
|
||||
impl BarrierWaitResult {
|
||||
/// Returns `true` if this thread from wait is the "leader thread".
|
||||
/// Returns `true` if this task from wait is the "leader task".
|
||||
///
|
||||
/// Only one thread will have `true` returned from their result, all other threads will have
|
||||
/// Only one task will have `true` returned from their result, all other tasks will have
|
||||
/// `false` returned.
|
||||
pub fn is_leader(&self) -> bool {
|
||||
self.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user