Mercurial > hg > Members > kono > rust-tutorial
view src/t16thread/src/main.rs @ 10:7eb649571bc6
add async example
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 18 Jan 2021 13:22:06 +0900 |
parents | aaba40049c28 |
children | 70ab6c2f7f6e |
line wrap: on
line source
use t16thread::mpsc_test::mainc; use t16thread::mpsc_test::mainm; use t16thread::racecondition::mainr; 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(); t16thread::mpsc_test::mainm(); t16thread::mpsc_test::mainc(); t16thread::racecondition::mainr(); t16thread::racecondition::mainu(); }