8
|
1 use t16thread::mpsc_test::mainc;
|
|
2 use t16thread::mpsc_test::mainm;
|
|
3 use t16thread::racecondition::mainr;
|
7
|
4
|
5
|
5 use std::thread;
|
|
6 use std::time::Duration;
|
|
7
|
7
|
8 fn main1() {
|
|
9 let v = vec![1, 2, 3];
|
|
10
|
|
11 let handle = thread::spawn(move || {
|
|
12 println!("Here's a vector: {:?}", v);
|
|
13 });
|
|
14 // drop(v);
|
|
15 handle.join().unwrap();
|
|
16 }
|
|
17
|
5
|
18 fn main() {
|
7
|
19 let handle = thread::spawn(|| {
|
|
20 for i in 0..10 {
|
5
|
21 println!("hi number {} from the spawned thread!", i);
|
|
22 thread::sleep(Duration::from_millis(1));
|
|
23 }
|
|
24 });
|
|
25
|
|
26 for i in 1..5 {
|
|
27 println!("hi number {} from the main thread!", i);
|
|
28 thread::sleep(Duration::from_millis(1));
|
|
29 }
|
7
|
30 handle.join().unwrap(); // without this, some data are dropped
|
|
31 // main1();
|
8
|
32 t16thread::mpsc_test::mainm();
|
|
33 t16thread::mpsc_test::mainc();
|
|
34 t16thread::racecondition::mainr();
|
5
|
35 } |