How to extend the Peterson algorithm to three or more processes

Peterson algorithm implements mutually exclusive access by pure software. But it only illustrates the mutual exclusion between the two processes, as shown below

-sharpdefine FALSE 0
-sharpdefine TRUE 1
-sharpdefine N 2

int turn;
int interested[N];

void enter_region(int process)
{
    int other;
    other = 1 - process;
    intersted[process] = TRUE;
    turn = process;
    while(turn == process && interested[other] == TRUE);
}

void leave_region(int process)
{
    interested[process] = FALSE;
}

how to extend to multiple processes?

Menu