Assume three threads share a BankAccount object with balance of zero (0) , a ReentrantLock named myLock, and a condition object on myLock named lowBalanceCondition, as shown below. Thread one calls withdraw(30) , then thread two calls withdraw(20) and thread three calls deposit(45) . If the starting balance is 0, what is the balance after the three calls?
Public void deposit(int dollars)
{
MyLock.lock() ;
Int newBalance = balance + dollars;
System.out.println("depositing") ;
Balance = newBalance;
MyLock.unlock() ;
}
Public void withdraw(int dollars)
{
MyLock.lock() ;
While (balance < dollars)
{
LowBalanceCondition.await() ;
}
Int newBalance = balance - dollars;
System.out.println("withdrawing") ;
Balance = newBalance;
MyLock.unlock() ;
}
A) 0
B) 15 or 25
C) 45
D) -5
Correct Answer:
Verified
Q26: What happens if we try to start
Q61: Consider an old fashioned telephone booth that
Q62: A GUI should be responsive to the
Q65: When is it a good idea to
Q68: What happens when a thread calls the
Q68: Exactly when does a thread finish in
Q69: Under what conditions are locks unnecessary for
Q70: Assume three threads share a BankAccount object
Q77: What is the relationship between synchronized code
Q79: Consider an old fashioned telephone booth that
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents