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:

Collectivism

A cultural value or social outlook that emphasizes the importance of groups and collective action over individual achievement or identity.

Corporate Social Responsibility

A business model that helps a company be socially accountable—to itself, its stakeholders, and the public. It involves practicing sustainable development and philanthropy.

Character Theories

A set of ideas that attempt to explain differences in individuals' moral qualities and behaviors.

Cultural Relativism

The belief that one should comprehend a person's values and behaviors through the lens of their unique cultural background.

Related Questions