Concurrency refers to the ability of a computer system to perform multiple tasks or processes simultaneously. It arises in three different contexts:
Concurrency can be challenging to implement correctly, as multiple threads or processes can interact with shared resources, leading to race conditions and other issues.
And so, mutual exclusion is a technique used in concurrent programming to prevent multiple threads or processes from accessing shared resources or critical sections at the same time. This could be done using software approaches, hardware approaches, or even using the OS itself.
Dijkstra reported an algorithm for mutual exclusion for two processes. As it is a software approach, we will look at code that will enforce this.
Figure 5.1 Mutual exclusion attempts.
This solution guarantees the mutual exclusion property, but has two drawbacks.
It goes through a few attempts before achieving the correct solution, that is Dekker’s algorithm.
Figure 5.2 Dekker’s algorithm.