Mercurial > hg > Members > kono > rust-tutorial
view src/t16thread/src/main.rs @ 7:8768d36c3b69
thread test
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 12 Jan 2021 14:34:05 +0900 |
parents | e869e24e5613 |
children | 2c6285996268 |
line wrap: on
line source
mod mpsc_test; // use racecondition; use racecondition::mainc; use std::thread; use std::time::Duration; fn main1() { let v = vec![1, 2, 3]; let handle = thread::spawn(move || { println!("Here's a vector: {:?}", v); }); // drop(v); handle.join().unwrap(); } fn main() { let handle = thread::spawn(|| { for i in 0..10 { println!("hi number {} from the spawned thread!", i); thread::sleep(Duration::from_millis(1)); } }); for i in 1..5 { println!("hi number {} from the main thread!", i); thread::sleep(Duration::from_millis(1)); } handle.join().unwrap(); // without this, some data are dropped // main1(); // mpsc_test::main_mpsc(); // mpsc_test::mainc(); racecondition::mainr(); }