- 567 名前:デフォルトの名無しさん [2023/09/29(金) 09:10:01.09 ID:F8aJXNq9.net]
- 下のコードで実行すると finish が出る順が
最後に completed したものが出て来るまで先に finish してても出て来ません 実際に finish した順通りに表示させるにはどう治せば良い? use std::thread; use std::time::Duration; fn test_thread() -> () { let mut handles = Vec::new(); for i in 0..5 { handles.push((i, thread::spawn(move || { println!("create {}", i); thread::sleep(Duration::from_millis(400 * (5 - (i - 2) * (i - 2)))); println!("{} completed", i); }))); } let mut completed = 0; for (i, handle) in handles { handle.join().unwrap(); println!("{} finish", i); completed += 1; } if completed != 5 { panic!("not finish"); } }
|

|