Terminate a loop from a different thread with Rust

こ雲淡風輕ζ 提交于 2020-01-15 04:01:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!