Peterson's Solution is a classical software-based solution to the critical section problem. However, due to the way modern computer architectures perform basic machine-language instructions, such as load from and store to memory, there are no guarantees that Peterson’s solution will work correctly on such architectures, but we still want to show this solution's good algorithmic thinking and consideration of the complexities involved in the solution.
Peterson's solution is based on two processes, P0 and P1, which alternate between their critical sections and remainder sections. More generally, Pi is the current process, and Pj (where j = 1 - i) is the 'other' process. The solution requires two shared data items: