Concurrency models with threads

We mainly use threads to perform a task that can be split into sub-problems, where the threads might need to communicate or share data with each other. Now, using the threading model as the baseline, there are different ways to structure our program and control access to shared data. A concurrency model specifies how multiple threads interact with instructions and data shared between them and how they make progress over time and space (here, memory).

Rust does not prefer any opinionated concurrency model and frees the developer in using their own models depending on the problem they are trying to solve through third party crates. So, other models of concurrency exist that includes the actor model implemented as a library in the actix crate. There are other models too, such as the work stealing concurrency model implemented by the rayon crate. Then, there is the crossbeam crate, which allows concurrent threads to share data from their parent stack frame and are guaranteed to return before the parent stack is deallocated.

There are two popular built-in concurrency models with which Rust provides us: sharing data with synchronization and sharing data by message passing.

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

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