Skip to content

Commit 3b73a6e

Browse files
committed
Remove old_io from trpl/concurrency.md
Also: the std_misc feature flag is removed; it's not needed in Beta. Hat tip to @tshepang in #23871 Fixes #24023
1 parent 80def6c commit 3b73a6e

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

src/doc/trpl/concurrency.md

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,14 @@ When `guard` goes out of scope, it will block execution until the thread is
8888
finished. If we didn't want this behaviour, we could use `thread::spawn()`:
8989

9090
```
91-
# #![feature(old_io, std_misc)]
9291
use std::thread;
93-
use std::old_io::timer;
94-
use std::time::Duration;
9592
9693
fn main() {
9794
thread::spawn(|| {
9895
println!("Hello from a thread!");
9996
});
10097
101-
timer::sleep(Duration::milliseconds(50));
98+
thread::sleep_ms(50);
10299
}
103100
```
104101

@@ -147,10 +144,7 @@ As an example, here is a Rust program that would have a data race in many
147144
languages. It will not compile:
148145

149146
```ignore
150-
# #![feature(old_io, std_misc)]
151147
use std::thread;
152-
use std::old_io::timer;
153-
use std::time::Duration;
154148
155149
fn main() {
156150
let mut data = vec![1u32, 2, 3];
@@ -161,14 +155,14 @@ fn main() {
161155
});
162156
}
163157
164-
timer::sleep(Duration::milliseconds(50));
158+
thread::sleep_ms(50);
165159
}
166160
```
167161

168162
This gives us an error:
169163

170164
```text
171-
12:17 error: capture of moved value: `data`
165+
8:17 error: capture of moved value: `data`
172166
data[i] += 1;
173167
^~~~
174168
```
@@ -187,10 +181,7 @@ only one person at a time can mutate what's inside. For that, we can use the
187181
but for a different reason:
188182

189183
```ignore
190-
# #![feature(old_io, std_misc)]
191184
use std::thread;
192-
use std::old_io::timer;
193-
use std::time::Duration;
194185
use std::sync::Mutex;
195186
196187
fn main() {
@@ -203,17 +194,17 @@ fn main() {
203194
});
204195
}
205196
206-
timer::sleep(Duration::milliseconds(50));
197+
thread::sleep_ms(50);
207198
}
208199
```
209200

210201
Here's the error:
211202

212203
```text
213-
<anon>:11:9: 11:22 error: the trait `core::marker::Send` is not implemented for the type `std::sync::mutex::MutexGuard<'_, collections::vec::Vec<u32>>` [E0277]
204+
<anon>:9:9: 9:22 error: the trait `core::marker::Send` is not implemented for the type `std::sync::mutex::MutexGuard<'_, collections::vec::Vec<u32>>` [E0277]
214205
<anon>:11 thread::spawn(move || {
215206
^~~~~~~~~~~~~
216-
<anon>:11:9: 11:22 note: `std::sync::mutex::MutexGuard<'_, collections::vec::Vec<u32>>` cannot be sent between threads safely
207+
<anon>:9:9: 9:22 note: `std::sync::mutex::MutexGuard<'_, collections::vec::Vec<u32>>` cannot be sent between threads safely
217208
<anon>:11 thread::spawn(move || {
218209
^~~~~~~~~~~~~
219210
```
@@ -232,11 +223,8 @@ guard across thread boundaries, which gives us our error.
232223
We can use `Arc<T>` to fix this. Here's the working version:
233224

234225
```
235-
# #![feature(old_io, std_misc)]
236226
use std::sync::{Arc, Mutex};
237227
use std::thread;
238-
use std::old_io::timer;
239-
use std::time::Duration;
240228
241229
fn main() {
242230
let data = Arc::new(Mutex::new(vec![1u32, 2, 3]));
@@ -249,7 +237,7 @@ fn main() {
249237
});
250238
}
251239
252-
timer::sleep(Duration::milliseconds(50));
240+
thread::sleep_ms(50);
253241
}
254242
```
255243

@@ -258,11 +246,9 @@ handle is then moved into the new thread. Let's examine the body of the
258246
thread more closely:
259247

260248
```
261-
# #![feature(old_io, std_misc)]
262249
# use std::sync::{Arc, Mutex};
263250
# use std::thread;
264-
# use std::old_io::timer;
265-
# use std::time::Duration;
251+
#
266252
# fn main() {
267253
# let data = Arc::new(Mutex::new(vec![1u32, 2, 3]));
268254
# for i in 0..2 {
@@ -272,6 +258,8 @@ thread::spawn(move || {
272258
data[i] += 1;
273259
});
274260
# }
261+
#
262+
# thread::sleep_ms(50);
275263
# }
276264
```
277265

0 commit comments

Comments
 (0)