Assume two threads share a BankAccount object with balance of zero (0) , and that the BankAccount class provides deposit and withdraw methods and has a ReentrantLock named myLock, as shown below. Thread one deposits $10 ten times and, concurrently, thread two withdraws $10 ten times. Which statement regarding the balance after all thread calls is definitely true?
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()
Int newBalance = balance - dollars;
System.out.println("withdrawing") ;
Balance = newBalance;
MyLock.unlock()
}
A) The balance could be zero or positive.
B) The balance is zero.
C) The balance could be zero or negative.
D) The balance is positive.
Correct Answer:
Verified
Q42: The _ method is useful only if
Q43: a(n. _ object is used to control
Q56: Examine the SharedData class shown below. Suppose
Q57: Which of the following statements is correct?
A)If
Q58: Examine the SharedData class shown below. Suppose
Q63: Assume two threads share a BankAccount object
Q64: Stale data occurs in multi-CPU machines when
Q72: Stale data occurs in multi-CPU machines when
Q74: Under what circumstances will a call to
Q80: Which of the following scenarios may not
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