Skip to content

Instantly share code, notes, and snippets.

@RandyMcMillan
Forked from rust-play/playground.rs
Last active January 18, 2025 15:13
Show Gist options
  • Save RandyMcMillan/b5ecab310c9a777f55f12b5cc844a9c1 to your computer and use it in GitHub Desktop.
Save RandyMcMillan/b5ecab310c9a777f55f12b5cc844a9c1 to your computer and use it in GitHub Desktop.
threads.rs
use std::thread;
const NTHREADS: u32 = 10;
// This is the `main` thread
fn main() {
// Make a vector to hold the children which are spawned.
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 the thread to finish. Returns a result.
let _ = child.join();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment