LayneYy
LayneYy
我是照着你写的思路写了一个,刚接触rust不久,可能有误解,麻烦大神帮我看看`use std::time::Duration; use futures::future::join_all; #[tokio::main] async fn main() { let mut v = Vec::new(); for _ in 1..10 { v.push(async move { println!("start {:?}", std::thread::current()); std::thread::sleep(Duration::from_millis(500)); }); }; join_all(v).await; }...
我这个版本是每隔0.5秒打印一个,并且线程都是主线程,是哪个姿势不正确吗
```rust use std::time::Duration; use futures::future::join_all; #[tokio::main] async fn main() { let mut v = Vec::new(); for _ in 1..10 { v.push(async move { println!("start {:?}", std::thread::current()); std::thread::sleep(Duration::from_millis(500)); }); }; join_all(v).await;...
期待程序能够并发执行,几乎同时打印10行,然后停留0.5秒结束主线程
tokio runtime 不会主动开多个线程吗
好的,谢谢,那篇文章得有时间多看几遍才能整明白,昨天晚上尝试了一下,被第二个例子劝退了,哈哈