The source code to set the name of a thread is given below. The given program is compiled and executed on UBUNTU 18.04 successfully.
// Rust program to set the name
// of a thread
use std::thread;
use std::time::Duration;
fn main() {
thread::Builder::new().name("MyThread".to_string()).spawn(move || {
println!("Thread is running");
});
thread::sleep(Duration::from_millis(500));
println!("Program finished");
}
Output:
$ rustc main.rs
$ ./main
Thread is running
Program finished
Explanation:
Here, we created a thread by assigning the name MyThread using the thread::Builder::new().name() method and printed the message "Thread is running".
Program/Source Code:
The source code to set the name of a thread is given below. The given program is compiled and executed on UBUNTU 18.04 successfully.
Output:
Explanation:
Here, we created a thread by assigning the name MyThread using the thread::Builder::new().name() method and printed the message "Thread is running".
need an explanation for this answer? contact us directly to get an explanation for this answer