Assume two threads share a BankAccount object with balance of zero (0) , and that the BankAccount class provides deposit and withdraw methods as shown below. Thread one deposits $10 ten times and, concurrently, thread two withdraws $10 ten times. Suppose a race condition occurs, and the race is finished first by thread one. What would you expect balance to be after all thread calls?
Public void deposit(int dollars)
{
Int newBalance = balance + dollars;
System.out.println("depositing") ;
Balance = newBalance;
}
Public void withdraw(int dollars)
{
Int newBalance = balance - dollars;
System.out.println("withdrawing") ;
Balance = newBalance;
}
A) $10
B) $20
C) $0
D) a negative amount
Correct Answer:
Verified
Q23: Which of the following definitely indicates that
Q27: Suppose thread one is downloading a 800KB
Q30: Which argument(s) present(s) the best case(s) for
Q34: The _ occurs when a thread that
Q42: Assume two threads share a BankAccount object
Q46: Examine the SharedData class shown below. Suppose
Q49: _ occur(s) if the effect of multiple
Q55: The _ method is called by a
Q58: If a thread sleeps after acquiring a
Q63: Calling the wait method in synchronized code
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