Peterson's solution requires two data items to be shared between the two processes:
int turn;
boolean flag[2];
- The variable turn indicates whose turn it is to enter its CS. That is, if
, then process
is allowed to execute in its CS.
- The flag array is used to indicate if a process is ready to enter its CS. For example, if
is true, this value indicates that
is ready to enter its CS.