23.4 Thread Synchronization
When multiple threads share an object and it’s modified by one or more of them, indeterminate results may occur (as we’ll see in the examples) unless access to the shared object is managed properly. If one thread is in the process of updating a shared object and another thread also tries to update it, it’s uncertain which thread’s update takes effect. Similarly, if one thread is in the process of updating a shared object and another thread tries to read it, it’s uncertain whether the reading thread will see the old value or the new one. In such cases, the program’s behavior cannot be trusted—sometimes the program will produce the correct results, and sometimes it won’t, and there won’t be any indication that the shared ...
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