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
Q43: a(n. _ object is used to control
Q48: Assume two threads share a BankAccount object
Q49: Assume two threads share a BankAccount object
Q50: A waiting thread is blocked until another
Q52: Consider the following change to the deposit
Q54: Consider the addFirst method of the LinkedList
Q56: Examine the SharedData class shown below. Suppose
Q57: Examine the SharedData class shown below. Suppose
Q58: If a thread sleeps after acquiring a
Q58: Examine the SharedData class shown below. Suppose
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