Spawn multiple threads

    0

    1

    Giovanny Gongora

    Codiga's Rust Recipes

    Mechanism for spawning native OS threads

    use std::thread;
    
    const NTHREADS: u32 = 6;
    // Vector to hold the spawned children.
    let mut children = vec![];
    for i in 0..NTHREADS {
      // Spin up another thread
      children.push(thread::spawn(move || {
        println!("this is thread number {}", i);
      }));
    }
    for child in children {
      // Wait for finish to return a result
      let _ = child.join();
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.