问题
I have a simple loop in a thread, and I'd like to stop the loop. Normally with Python, I would use a global variable to stop the loop, but I don't know for Rust.
I heard about channels, but I don't know how to pass a channel Receiver into my function which starts a new thread.
回答1:
Channels seem like overkill for a simple loop condition. You can use an atomic variable instead which can be shared across threads.
来源:https://stackoverflow.com/questions/41465573/terminate-a-loop-from-a-different-thread-with-rust