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
Q26: What happens if we try to start
Q55: The _ method is called by a
Q57: Examine the SharedData class shown below. Suppose
Q58: Examine the SharedData class shown below. Suppose
Q60: Examine the SharedData class shown below. Suppose
Q60: Which phrase best describes the purpose of
Q61: Consider an old fashioned telephone booth that
Q64: Stale data occurs in multi-CPU machines when
Q68: What happens when a thread calls the
Q71: Class MyClass has a single ReentrantLock object,
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