A savings account object holds a nonnegative balance

Assignment Help Basic Computer Science
Reference no: EM13535269

A savings account object holds a nonnegative balance, and provides deposit(k) and withdraw(k) methods, where deposit(k) adds k to the balance, and withdraw(k) subtracts k, if the balance is at least k, and otherwise blocks until the balance becomes k or greater.

Implement this savings account using locks and conditions.

Now suppose there are two kinds of withdrawals: ordinary and preferred. Devise an implementation that ensures that no ordinary withdrawal occurs if there is a preferred withdrawal waiting to occur. Suppose there are two threads: one account attempting an ordinary withdrawal and another account attempting a preferred withdrawal. Both are attempting to do this at the same time. The account performing the preferred withdrawal should have priority attempting to make the withdrawal.

Now let us add a transfer() method that transfers a sum from one account to another:

void transfer(int k, Account reserve) {

lock.lock();

try {

reserve.withdraw(k);

deposit(k);

} finally {lock.unlock();}

}
4. We are given a set of 10 accounts, whose balances are unknown.
At 1:00, each of n threads tries to transfer $100 from another account
into its own account. At 2:00, a Boss thread deposits $1000 to each
account. Is every transfer method called at 1:00 certain to return?
If so, provide a test mechanism that verifies this.
If not, please explain why this is not so.

Reference no: EM13535269

Questions Cloud

Ability to apply the concepts : The goal of this project is for you to demonstrate your ability to apply the concepts
What is spectroscopic and photometric parallaxes : what is Spectroscopic and Photometric Parallaxes ? Define specific heat capacity and thermal capacity.
What is its velocity and acceleration : A projectile is fired with an initial velocity of 20 m/s at 50° above horizontal. At the projectile's highest point, what is its velocity?.What is its acceleration?
What is the pressure when the piston is at the top : A cylinder of a car's enginehas a volume of .725 L when the piston is at the bottom of the cylinder.When the piston is at the top of the cylinder it has a volume of 0.050 L.If the cylinder is filled with air at a pressure of 1 atm when the pistonis a..
A savings account object holds a nonnegative balance : A savings account object holds a nonnegative balance, and provides deposit(k) and withdraw(k) methods, where deposit(k) adds k to the balance, and withdraw(k) subtracts k, if the balance is at least k, and otherwise blocks until the balance be..
Resulting in considerable change in thermodynamic properties : A certain puddle of water has 1025 identical water molecules. As the temperature of this puddle falls to 0°C and below, the puddle freezes, resulting in a considerable change in the thermodynamic properties of this system.
In the absence of an applied torque a rigid body : In the absence of an applied torque a rigid body with three distinct principal moments of inertia given by I1, I2 and I3 is rotating freely about a fixed point inside the body.
Sample cybersecurity profile : Sample Cybersecurity Profile
What is the surface temperature of betelgeuse : What is the surface temperature of Betelgeuse, a red giant star in the constellation of Orion, which radiates with a peak wavelength of about 970 nm?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd