-
Book Overview & Buying
-
Table Of Contents
Rust for C++ Developers
By :
Shared data must be synchronized across threads to be shared properly. This means that reads and writes must both be atomic operations. Many languages offer a suite of synchronization primitives to allow users to deal with these issues, and Rust is no exception. In this section, we'll examine how Rust deploys these special types of objects while still disallowing data races in safe code.
Synchronization primitives are a special set of objects that can be used to make data operations in a section of code occur atomically relative to every other invocation of that section of code. The most common synchronization primitive is a mutex, which stands for "mutual exclusion." Mutexes are called other names in some platform APIs, such as critical sections, but in the end, the goal of a mutex is to ensure that only one thread can execute a specific section of code at a time.
Typical usage of a mutex in most APIs involves...