Examlex

Solved

Assume Three Threads Share a BankAccount Object with Balance of Zero

question 68

Multiple Choice

Assume three threads share a BankAccount object with balance of zero (0) , a ReentrantLock named myLock, and has 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 and after the waiting threads have had a chance to run? public void deposit(int dollars)
{
MyLock.lock() ;
Int newBalance = balance + dollars;
System.out.println("depositing") ;
Balance = newBalance;
LowBalanceCondition.signalAll() ;
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:

Gracile Australopithecines

One member of the genus Australopithecus possessing a more lightly built chewing apparatus; likely had a diet that included more meat than that of the robust australopithecines.

Human Ancestors

Prehistoric species and genera that are considered predecessors of modern humans in the evolutionary lineage.

Homo Erectus

An extinct species of early human that lived throughout Africa and Eurasia from approximately 2 million to 100,000 years ago.

Acheulean Tool

Prehistoric stone tools associated with the Lower Paleolithic period, characterized by large hand-axes and cleavers.

Related Questions