Message passing between threads has been an issue in many standard libraries and programming languages since many rely on the user to apply locking. This leads to deadlocks and is somewhat intimidating for newcomers, which is why many developers were excited when Go popularized the concept of channels, something that we can also find in Rust. Rust's channels are great for designing a safe, event-driven application in just a few lines of code without any explicit locking.
Using channels to communicate between threads
How to do it...
Let's create a simple application that visualizes incoming values on the command line:
- Run cargo new channels to create a new application project and open the directory in Visual Studio...