Skip to content

Commit

Permalink
sync: Barrier doc should use task, not thread (#3780)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn authored May 13, 2021
1 parent 9ff7d8c commit d846bf2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions tokio/src/sync/barrier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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);

Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d846bf2

Please sign in to comment.