Chapter 19
Thread-Safe Objects
The most common way threads interact is by sharing objects. Objects that can be freely shared without the need for threads to coordinate accesses are said to be thread-safe. Immutable objects are naturally thread-safe, but mutable objects need to rely on internal strategies to ensure thread-safety, often by locking. Different locking designs allow thread-safe objects to expose more or less of their synchronization strategy, resulting in a trade-off between flexibility and risk of misuse.
19.1 Immutable Objects
Earlier examples have shown that programs can easily behave incorrectly when data is shared by multiple threads. What all these examples have in common is that the data being shared is mutable: an integer ...
Get Functional and Concurrent Programming: Core Concepts and Features now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.