彼得森的解决方案:为什么它有时在非抢占式调度中不起作用?

时间:2015-11-05 01:58:12

标签: mutual-exclusion

为什么当进程调度有时不会先发制人时,Peterson对互斥问题的解决方案是否有效?

有人可以帮助我理解彼得森的解决方案吗?

感谢您的时间和帮助!

彼得森的解决方案:

#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*/
}

0 个答案:

没有答案