Examlex

Solved

Assume Three Threads Share a BankAccount Object with Balance of Zero

question 51

Multiple Choice

Assume three threads share a BankAccount object with balance of zero (0) , a ReentrantLock named myLock, and 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? 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() ;
While (balance < dollars)
{
LowBalanceCondition.await() ;
}
Int newBalance = balance - dollars;
System.out.println("withdrawing") ;
Balance = newBalance;
MyLock.unlock() ;
}


Definitions:

Common Stock

An equity security representing ownership in a corporation, entitling holders to a share of the corporation's residual assets and earnings.

Acquisition Transaction

A financial deal or agreement in which one company takes control of another company, either through a direct purchase of its shares or assets.

Fair Values

The plural form indicating multiple instances or assessments of the market values of assets or liabilities at a given time.

Credit Balance

Represents a situation where the amount of credits in an account exceeds the debits, often indicating the amount owed to the account holder or available for future use.

Related Questions