Concurrency in RUST
Rust provides built-in support for concurrency using threads and channels. Here's an example of using threads to execute some work in parallel:
css
use std::thread;
fn main() {
let handle = thread::spawn(|| {
for i in 1..=10 {
println!("Thread {}: {}", thread::current().name().unwrap(), i);
}
});
for i in 1..=10 {
println!("Main thread: {}", i);
}
handle.join().unwrap();
}
No comments:
Post a Comment