Summary
In this chapter, we covered the basics of concurrency and multi-threaded programming in Rust. We started by reviewing the need for concurrent programming models. We understood the differences between the concurrent and parallel execution of programs. We learned how to spawn new threads using two different methods. We handled errors using a special Result
type in the thread module and also learned how to check whether the current thread is panicking. We looked at how threads are laid out in process memory. We discussed two techniques for synchronizing processing across threads – message-passing concurrency and shared-state concurrency, with practical examples. As a part of this, we learned about channels, Mutex
and Arc
in Rust, and the role they play in writing concurrent programs. We then discussed how Rust classifies data types as thread-safe or not, and saw how to pause the execution of the current thread.
This concludes the chapter on managing concurrency in Rust...