Thread safety
Traditional programming with threads is very difficult to get right if you allow the different threads to work on the same mutable data, or so-called shared memory. When two or more threads simultaneously change data, then data corruption (also called data racing) can occur due to the unpredictability of the thread's scheduling.
In general, data (or a type) is said to be thread-safe when its contents will not be corrupted by the execution of different threads. Other languages offer no such help, but the Rust compiler simply forbids non-thread-safe situations to occur. The same ownership strategy that we looked at to allow Rust to prevent memory safety errors also enables you to write safe, concurrent programs.
Consider the following ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access