Chapter 14
- Critical sections indicate shared resources that are accessed by multiple processes or threads in a concurrent application, which can lead to unexpected, and even erroneous, behaviors.
- A race condition occurs when two or more threads/processes access and alter a shared resource simultaneously, resulting in mishandled and corrupted data.
- The root cause of a race condition is multiple threads/processes reading in and altering a shared resource simultaneously. When all of the threads/processes finish their execution, only the result of the last thread/process is registered.
- Since race conditions arise when multiple threads or processes access and write to a shared resource simultaneously, the solution is to isolate the execution of different threads/processes, especially when interacting with the shared resource. With locks, we can turn a shared resource in a concurrent program into a critical section, whose data integrity is guaranteed to be protected. ...