rustHow to dump a thread in Rust?
Dumping a thread in Rust is done using the thread::park() function. This function will block the current thread until it is unparked.
use std::thread;
let handle = thread::spawn(|| {
println!("Hello from a thread!");
});
handle.thread().unpark();
thread::park();
The code above will spawn a new thread and then unpark it. The main thread will then be parked until the spawned thread is finished.
thread::spawn(): spawns a new threadhandle.thread().unpark(): unpark the spawned threadthread::park(): park the main thread
Helpful links
More of Rust
- How to use regex to match a double quote in Rust?
- How to match a URL with a regex in Rust?
- How to insert an element into a Rust HashMap if it does not already exist?
- How to replace strings using Rust regex?
- How to use captures_iter with regex in Rust?
- How to use regex to match a group in Rust?
- How to perform matrix operations in Rust?
- How to sort a Rust HashMap?
- How to create a HashMap of structs in Rust?
- How to use 'or' in Rust regex?
See more codes...