Rust

[Rust lang] 83. multiple threads

밍글링글링 2023. 3. 30.
728x90
use std::thread;

fn main() {
    /*
        let join_handle = thread::spawn(|| {
            println!("I am printing something");
        });

        join_handle.join();
    */

    let mut join_vec = vec![];
    for _ in 0..10 {
        let handle = thread::spawn(|| {
            println!("I am printing something");
        });
        join_vec.push(handle);
    }

    join_vec.into_iter().for_each(|handle| handle.join().unwrap());
}
728x90

'Rust' 카테고리의 다른 글

[Rust lang] 85. clippy  (0) 2023.03.30
[Rust lang] 84. mutex  (0) 2023.03.30
[Rust lang] 82. cow  (0) 2023.03.30
[Rust lang] 81. type alias and todo macro  (0) 2023.03.30
[Rust lang] 80. rust 1.59  (0) 2023.03.30

댓글