April 2026
Intermediate
631 pages
16h 20m
English
This section provides code solutions for the practice exercises in Section 14.9. The code is largely self-explanatory; however, we have included comments and additional explanations wherever necessary to enhance understanding.
Completing multithreaded execution with print statements
use std::thread;fn main() { let mut thread_vec = vec![]; for i in 0..10 { thread_vec.push(thread::spawn(|| { println!("Hi from the thread"); })); } // The code below will make sure that all the threads go to completion for i in thread_vec { i.join(); }}
Parallel summation using multiple threads
use std::thread;fn main() { let handle_1 = thread::spawn(|| { let mut sum = 0; let range = 0..=1_000; for num in range { sum += num; } sum }); let ...
Read now
Unlock full access