我正在网上阅读一些关于关键区域、进入协议和退出协议的示例,并且很难弄清楚。 http://pages.cs.wisc.edu/~dusseau/Classes/CS537-S01/SampleQuizzes/sol2.html
class BankAccount {
private int turn = 0;
private boolean lock = {true, true};
private int balance;
private int accountNumber;
BankAccount(int acct) {
accountNumber = acct;
balance = 0;
}
// tellerID is either 0 or 1
public void deposit(int amount, int tellerID) {
lock[tellerID] = true;
turn = 1 - tellerID;
while (lock[1-tellerID] && turn == (1 - tellerID));
balance += amount;
lock[tellerID] = false;
}
}
这个例子的入口协议、出口协议和临界区是什么?至于临界区,是互斥、饿死还是会陷入僵局?