Minege
Minege

Reputation: 37

Terminate a loop from a different thread with Rust

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.

Upvotes: 2

Views: 2084

Answers (1)

the8472
the8472

Reputation: 43042

Channels seem like overkill for a simple loop condition. You can use an atomic variable instead which can be shared across threads.

Upvotes: 3

Related Questions