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

  Computing downtime in telephone per year

Telephone system has an availability of 99.999 percent. How much downtime is that per year? Express your answer in a way that is easy for someone to understand.

  Show schematically a function definition line

Show schematically a function definition line ? And how u would call (execute) the function in a MATLAB program?

  How entry level manager adjust able to grow into upper level

How do you think an entry level manager has to adjust to be able to grow into an upper level manager

  How do you define the frequency or cycling

Filters exist in natural systems, biosystems, psychsystems, mechanical, etc. Give an example of filtering in nonelectronic area

  Draw a structured flowchart describing the steps

1. Draw a structured flowchart describing the steps you would take to cook popcorn in a microwave oven. Include at least one decision. 2. Create the pseudocode to go along with the flowchart created in question above.

  Write a program that prompts for a pattern of 6 dice

Write a program that prompts for a pattern of 6 dice and then counts the number of throw necessary to get that pattern to appear.

  Determine the highest bit rate possible for a circuit

1. Determine the number of conditions possible for a binary code

  Determine if the string s=s1s2...sk

Suppose we want to determine if the string s=s1s2...sk is a substring much larger string a1a2...an. One approach is to compute h(s) with some hash function h.

  A local department store hires you to write

A local department store hires you to write an automated checkout program to expedite customers in a hurry. The checkout line can only accept five items for any one purchase. Design a program that asks for the price of each item, and then displays..

  Describe virtual private network (vpn) tunneling

Describe some of the PPP configuration options that a network administrator can utilize in this network technology.

  Explaining data visualization form of business intelligence

Is data visualization a form of business intelligence? Describe why or why not? What security issues are related with data visualization?

  What is the const keyword in c++ and why would you use

What is the const keyword in C++? Why would you use the const keyword

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