Multiple Choice
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
Correct Answer:
Verified
Q14: Which of the following class declarations could
Q24: Assume two threads share a BankAccount object
Q34: _ occur(s) if the effect of multiple
Q40: Calling the wait method in synchronized code
Q41: Consider the addFirst method of the LinkedList
Q51: In which method are the tasks that
Q58: The _ interface is designed to encapsulate
Q62: A waiting thread is blocked until another
Q66: Consider an old fashioned telephone booth that
Q70: The _ method does not actually cause