How to check if a thread has finished in Rust?

Viewed 8293

When I spawn a thread in Rust, I get a JoinHandle, which is good for... joining (a blocking operation), and not much else. How can I check if a child thread has exited (i.e., JoinHandle.join() would not block) from the parent thread? Bonus points if you know how to kill a child thread.

I imagine you could do this by creating a channel, sending something to the child, and catching errors, but that seems like needless complexity and overhead.

5 Answers

I think Arc can be used to solve this problem If the thread exits, the reference counter is reduced by one

Related