Implementing safe mutable access

We want to ensure safe and mutable access of data, which will allow multiple threads to access the resource without having data races. The ownership model of Rust enables this functionality. You will learn about locks that will help you keep track of your data when you have multiple threads making modifications to it. We have the atomic reference count Arc<T> in Rust, which at runtime will keep track of the count and allow the developer to share the ownership of the data across threads.

In this recipe, we will use mutex<T>. This allows us to safely mutate a shared data value across multiple threads. For example, we have data where mutex will ensure only one thread would be able to mutate the value inside it at a time.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.253.210