I was reading through some examples online regarding about the critical region, entry protocol and exit protocol, and had a hard time figuring out. 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;
}
}
What's the entry protocol, exit protocol and critical region for this example? and as for the critical region, is it mutual exclusion, starvation or will it result in a deadlock?