Multiple Choice
Assume three threads share a BankAccount object with balance of zero (0) , a ReentrantLock named myLock, and has 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 and after the waiting threads have had a chance to run?
Public void deposit(int dollars)
{
MyLock.lock() ;
Int newBalance = balance + dollars;
System.out.println("depositing") ;
Balance = newBalance;
LowBalanceCondition.signalAll() ;
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
Correct Answer:
Verified
Q1: Assume two threads share a BankAccount object
Q4: Assume two threads share a BankAccount object
Q20: Under what circumstances will a call to
Q25: Suppose thread one is downloading a large
Q26: The sleep method is terminated with a(n)
Q42: When a sleeping thread is interrupted, an
Q48: What should be done to get the
Q66: The _ occurs when a thread that
Q69: The _ method is called by a
Q74: A GUI should be responsive to the