Skip to content

Commit 9300db3

Browse files
committed
threads
1 parent 6c97924 commit 9300db3

3 files changed

Lines changed: 24 additions & 23 deletions

File tree

course/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use basics;
22
use myutils::stuff;
33
use myutils::testing;
44
//use guessgame
5-
use paral;
5+
use paral::threads;
66

77
fn main() {
88
basics::basics();
@@ -15,5 +15,5 @@ fn main() {
1515
//guessgame::guess_game();
1616
intmut::intmut();
1717
intmut::weakrefs();
18-
paral::threads();
18+
threads::demo();
1919
}

paral/src/lib.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1 @@
1-
use std::{thread, time::Duration};
2-
3-
pub fn threads() {
4-
println!("Threads");
5-
let handle = thread::spawn(|| {
6-
for i in 1..10 {
7-
println!("hi number {} from the spawned thread!", i);
8-
thread::sleep(Duration::from_millis(1));
9-
}
10-
});
11-
handle.join().unwrap();
12-
println!("Joined");
13-
14-
let v = vec![1, 2, 3];
15-
let handle = thread::spawn(move || {
16-
for i in 1..10 {
17-
println!("{}: Here's a vector: {:?}", i, v);
18-
}
19-
});
20-
handle.join().unwrap();
21-
}
1+
pub mod threads;

paral/src/threads.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use std::{thread, time::Duration};
2+
3+
pub fn demo() {
4+
println!("Threads");
5+
let handle = thread::spawn(|| {
6+
for i in 1..10 {
7+
println!("hi number {} from the spawned thread!", i);
8+
thread::sleep(Duration::from_millis(1));
9+
}
10+
});
11+
handle.join().unwrap();
12+
println!("Joined");
13+
14+
let v = vec![1, 2, 3];
15+
let handle = thread::spawn(move || {
16+
for i in 1..10 {
17+
println!("{}: Here's a vector: {:?}", i, v);
18+
}
19+
});
20+
handle.join().unwrap();
21+
}

0 commit comments

Comments
 (0)