mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-02-24 21:32:15 +08:00
19 lines
419 B
Rust
19 lines
419 B
Rust
|
use std::thread;
|
||
|
use std::time::Duration;
|
||
|
|
||
|
fn main() {
|
||
|
let handle = thread::spawn(|| {
|
||
|
for i in 1..10 {
|
||
|
println!("hi number {} from the spawned thread!", i);
|
||
|
thread::sleep(Duration::from_millis(1));
|
||
|
}
|
||
|
});
|
||
|
|
||
|
handle.join().unwrap();
|
||
|
|
||
|
for i in 1..5 {
|
||
|
println!("hi number {} from the main thread!", i);
|
||
|
thread::sleep(Duration::from_millis(1));
|
||
|
}
|
||
|
}
|