January 2019
Beginner to intermediate
554 pages
13h 31m
English
We also have APIs that can be used to configure threads by setting their properties such as the name or their stack size. For this, we have the Builder type from the thread module. Here's a simple program that creates a thread and spawns it using the Builder type:
// customize_threads.rsuse std::thread::Builder;fn main() { let my_thread = Builder::new().name("Worker Thread".to_string()) .stack_size(1024 * 4); let handle = my_thread.spawn(|| { panic!("Oops!"); }); let child_status = handle.unwrap().join(); println!("Child status: {}", child_status);}
In the preceding code, we use the Builder::new, method followed by calling the name and stack_size methods to add a name to our thread and its stack size respectively. We then ...
Read now
Unlock full access