Skip to content

Commit c4ba0a6

Browse files
authored
Rollup merge of #113202 - guilliamxavier:patch-1, r=workingjubilee
std docs: factorize literal in Barrier example Motivated by https://www.reddit.com/r/rust/comments/rnh5hu/barrier_question_barrier_does_not_sync_many/ (but maybe not worth it?)
2 parents 2a3766e + e34ff93 commit c4ba0a6

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

library/std/src/sync/barrier.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ use crate::sync::{Condvar, Mutex};
1313
/// use std::sync::{Arc, Barrier};
1414
/// use std::thread;
1515
///
16-
/// let mut handles = Vec::with_capacity(10);
17-
/// let barrier = Arc::new(Barrier::new(10));
18-
/// for _ in 0..10 {
16+
/// let n = 10;
17+
/// let mut handles = Vec::with_capacity(n);
18+
/// let barrier = Arc::new(Barrier::new(n));
19+
/// for _ in 0..n {
1920
/// let c = Arc::clone(&barrier);
2021
/// // The same messages will be printed together.
2122
/// // You will NOT see any interleaving.
@@ -105,9 +106,10 @@ impl Barrier {
105106
/// use std::sync::{Arc, Barrier};
106107
/// use std::thread;
107108
///
108-
/// let mut handles = Vec::with_capacity(10);
109-
/// let barrier = Arc::new(Barrier::new(10));
110-
/// for _ in 0..10 {
109+
/// let n = 10;
110+
/// let mut handles = Vec::with_capacity(n);
111+
/// let barrier = Arc::new(Barrier::new(n));
112+
/// for _ in 0..n {
111113
/// let c = Arc::clone(&barrier);
112114
/// // The same messages will be printed together.
113115
/// // You will NOT see any interleaving.

0 commit comments

Comments
 (0)