3

なじみのない方のために説明すると、プロセス調整に使用される 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
}

私の質問は、このアルゴリズムがデッドロックを引き起こす可能性があるかどうかです。

4

1 に答える 1

1

いいえ、デッドロックの可能性はありません。あなたが待っている唯一の場所はwhileループです。また、process変数はスレッド間で共有されておらず、それらは異なりますが、turn変数は共有されています。したがって、常に複数のスレッドのtrue状態を取得することは不可能です。turn == processしかし、とにかくあなたの解決策はまったく正しくありません。ピーターソンのアルゴリズムはNo_Of_Processes、コード内のようなものではなく、2 つの同時スレッドのみを対象としています。プロセスの元のアルゴリズムでは、Nデッドロックが発生する可能性があります。

于 2011-05-15T13:22:39.050 に答える