【发布时间】:2017-04-29 22:14:44
【问题描述】:
我正在尝试了解 Peterson 提供的互斥问题的解决方案。所以这里是彼得森的互斥解决方案:
int No_Of_Processes; // Number of processes
int turn; // Whose turn is it?
int interested[No_Of_Processes]; // All values initially FALSE
void enter_region(int process) {
int other; // number of the other process
other = 1 - process; // the opposite process
interested[process] = TRUE; // this process is interested
turn = process; // set flag
while(turn == process && interested[other] == TRUE); // wait
}
void leave_region(int process) {
interested[process] = FALSE; // process leaves critical region
}
我不明白他为什么在空闲的 while 循环中使用 turn == 进程。这看起来很矛盾,因为如果另一个进程想要进入临界区,则将轮次设置为另一个进程,这意味着前一个进程也可以进入临界区,而不管感兴趣的缓冲区的内容。
【问题讨论】:
标签: c operating-system