-
Notifications
You must be signed in to change notification settings - Fork 0
/
mine.rs
62 lines (56 loc) · 1.26 KB
/
mine.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#![allow(unused)]
use tokio::{
runtime,
//task,
time::{sleep, Duration},
};
/*
use std::{
time::Duration,
thread,
};
*/
use std::sync::{Mutex, Arc};
fn main(){
let rt = runtime::Builder::new_multi_thread()
.worker_threads(1)
.enable_all()
.build()
.unwrap();
rt.block_on(async{
for i in 0..30{
println!("\x1b[32mLOOPING SPAWN()\x1b[0m");
tokio::spawn(async move{
println!("\x1b[34;1mhere {}\x1b[0m", i);
sleep(Duration::from_millis(1000)).await;
println!("\x1b[33;1mhere {}\x1b[0m", i);
});
}
let mut x = 0;
for i in 0..300000000{
x += 1;
}
println!("spin {}", x);
});
}
/*
fn main(){
//let mut rt = tokio::runtime::Runtime::new().unwrap();
let rt = runtime::Builder::new_current_thread().build().unwrap();
rt.block_on(async{
println!("\x1b[93mMY MAIN STARTS NOW\x1b[0m");
let mut data = Arc::new(Mutex::new(0));
for i in 0..3 {
println!("\x1b[93mMY MAIN SPAWNING TASKS\x1b[0m");
let mut wrapper = Arc::clone(&data);
let handle = tokio::spawn(async move{
println!("\x1b[93mhello {}, {:?}\x1b[0m", i, thread::current().id());
let mut wrapper = wrapper.lock().unwrap();
*wrapper += 1;
});
handle.await;
}
println!("\x1b[93mMY MAIN EXITS WITH DATA : {}\x1b[0m", data.lock().unwrap());
})
}
*/