1

Why doesn't Peterson’s solution to the mutual-exclusion problem work when process scheduling is non-pre-emptive sometimes?

Can someone please help me understand in the context of peterson's solution?

Thank you for your time and help!

Peterson's solution:

#define FALSE 0 /* number of processes */
#define TRUE 1
#define N 2

int turn; /* who's turn is it? */
int interested[N];

void enter_region(int process);
{
int other;

other = 1 - process; /* the opposite of process*/
interested[process] = TRUE; /* show that you are interested*/
turn = process; /* set flag */
while (turn == process && interested[other] == TRUE) /* null statement */
}

void leave_region(int process) /* process: who is leaving */
{
interested[process] = FALSE; /* indicate departure from critical region*/
}
Andremoniy
  • 34,031
  • 20
  • 135
  • 241
user5527252
  • 73
  • 1
  • 7

0 Answers0