projects
/
rust-101.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix pycco-rs to get rid of empty code blocks
[rust-101.git]
/
workspace
/
src
/
part15.rs
diff --git
a/workspace/src/part15.rs
b/workspace/src/part15.rs
index 1a6873e2009931dfeeba396768646e1f8cafb961..6982579bad7b7570e158679e6af04f928c8594c8 100644
(file)
--- a/
workspace/src/part15.rs
+++ b/
workspace/src/part15.rs
@@
-3,6
+3,7
@@
use std::sync::{Arc, Mutex};
use std::thread;
use std::sync::{Arc, Mutex};
use std::thread;
+use std::time::Duration;
// The derived `Clone` implementation will clone the `Arc`, so all clones will actually talk about the same counter.
// The derived `Clone` implementation will clone the `Arc`, so all clones will actually talk about the same counter.
@@
-36,7
+37,7
@@
pub fn main() {
let counter1 = counter.clone();
let handle1 = thread::spawn(move || {
for _ in 0..10 {
let counter1 = counter.clone();
let handle1 = thread::spawn(move || {
for _ in 0..10 {
- thread::sleep
_ms(15
);
+ thread::sleep
(Duration::from_millis(15)
);
counter1.increment(2);
}
});
counter1.increment(2);
}
});
@@
-45,14
+46,14
@@
pub fn main() {
let counter2 = counter.clone();
let handle2 = thread::spawn(move || {
for _ in 0..10 {
let counter2 = counter.clone();
let handle2 = thread::spawn(move || {
for _ in 0..10 {
- thread::sleep
_ms(20
);
+ thread::sleep
(Duration::from_millis(20)
);
counter2.increment(3);
}
});
// Now we watch the threads working on the counter.
for _ in 0..50 {
counter2.increment(3);
}
});
// Now we watch the threads working on the counter.
for _ in 0..50 {
- thread::sleep
_ms(5
);
+ thread::sleep
(Duration::from_millis(5)
);
println!("Current value: {}", counter.get());
}
println!("Current value: {}", counter.get());
}