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();
      }
      
      Rust language logo

      Spawn multiple threads

      Codiga's Rust Recipes

      Mechanism for spawning native OS threads

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.