Implement savings account using locks and conditions

Assignment Help JAVA Programming
Reference no: EM13709548

Problem 1:

A savings account object holds a non-negative 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 un-

til the balance becomes k or greater. getbalance() gives the current balance.

1. Implement this savings account using locks and conditions. Test by using the 3 functions.

2. 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.

Problem 2:

Consider the following conditions: An enqueuer waiting on a full-queue or a dequeuer waiting on an empty queue sleep indefinitely. unless woken up by another thread. A thread must send a signal ONLY when it adds an element to an empty queue or removes an element from a full-queue.

1. Implement a bounded partial queue using a signaling mechanism that signals to all waiting dequeuers.

2. Implement the bounded partial queue by using a signaling mechanism (your own scheme) that signals to only one waiting dequeuer or enqueuer. and ensure that the lost-wake-up problem does not happen.

Problem 3:

We have n threads, each of which executes method too () followed by bar 0. We want to add synchronization to ensure that no thread starts executing bar() until all threads have finished executing f oo (). To achieve this, we will in¬sert some barrier code between the two methods. Implement the following two schemes for bather code:

• Use a shared counter protected by test-and-test-and-set lock. Each thread locks the counter, increments it, releases the lock, and repeatedly reads the counter until it reaches n.

• Use an n-element Boolean array A. Initially all entries are 0. When thread 0 executes its bather, it sets b CO] to 1, and repeatedly reads b - 11 until it becomes 1. Every other thread i, repeatedly reads b [i - 1] until it becomes 1, then it sets b [i] to 1, and repeatedly reads b [n - 1] until it becomes 1.

Implement both these schemes in Java. Each of the methods too 0 and bar() just sleeps for 20 milliseconds. Test the two schemes for n = 16. Run each scheme at least ten times, measure the total runtime in each test run, discard the highest and lowest values, take the average, and use it to compare the two schemes.

Which performs better? Can you explain the reason? You can run the experiments on ecen5033.colorado.edu. Submit the code as well as experimental results.

Reference no: EM13709548

Questions Cloud

Demonstrate your learning : Hand-in Assignments are one way for you to demonstrate your learning. The Hand-in Assignments provide an opportunity to apply concepts and strategies to an authentic context.
What are the three basic functions of a firm-organisation : What are the three basic functions of a firm/organisation? Do all firms/organisations (private, government, not-for-profit) perform these three functions?
Prepare targeted plan to present your strategies to recruit : Prepare a targeted plan in which you present your detailed strategies to recruit and select 20 Engineers to hire (full-time or part-time) within 8 months. Focus on job-relatedness.
Implement savings account using locks and conditions : A savings account object holds a non-negative balance - Use a shared counter protected by test-and-test-and-set lock. Each thread locks the counter, increments it, releases the lock, and repeatedly reads the counter until it reaches n.
Absolute advantage of any country in any industry : Absolute advantage of any country in any industry - Find a recent news article covering that topic.
Discuss the implications of various market structures : Discuss the implications of various market structures
Describe processes codified in erp : Describe the different processes codified in ERP for organizations and describe the ways to reduce the risks. Does this limit innovation and if so, how can that risk be reduced.
Name two organic compounds that cannot be extracted : Name two organic compounds that cannot be extracted effectively from an aqueous solution by means of an immiscible organic solvent such as ether or cyclohexane.

Reviews

Write a Review

JAVA Programming Questions & Answers

  File integrity checker - tripwire

Write a program that will perform some of the basic tasks accomplished by a file integrity checker such as Tripwire.

  Build the gui layout of the gamecreate a class called

build the gui layout of the gamecreate a class called pipegameapp.java which will be the main game user interface. the

  Create a dice game that uses a six-sided die

Create a dice game that uses a six-sided die - Using switch statements print the face of the die based on the value obtained.

  What is relationship between hashing and digital signatures

The security advantages of using two-factor authentication, such as the integrated fingerprint reader in the more recent iPhone models, particularly to support internet services (such as online banking)

  Write a statement to create a jframe object

Write a statement to create a JFrame object with a title of "My GUI Application" - Write a Java statement to have the object from the question above manage its display area by dividing it into 3 rows which have 4 columns each.

  Need a console program

Need a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed).

  Problem 1 the queue adta queue is a fundamental abstract

problem 1. the queue adta queue is a fundamental abstract data type. it is an ordered collection of items in which the

  Computing the time complexity using the big-o notation

You are required to calculate the time complexity using the big-O notation of the Algorithm_2 given by the following methods defined by the following Java code.

  Create a deque class based on the discussion of deques

Create a Deque class based on the discussion of deques (double-ended queues) in this chapter. It should include insertLeft(), insertRight(), removeLeft(), removeRight(), isEmpty(), and isFull() methods.

  Discuss the legal ramifications of the division of condo

Discuss the legal ramifications of the division of condo, BioTech and other assets. Would it make any difference if Violet sold the property after filing for the dissolution of marriage?

  Carry out additions and subtraction

You are to design a Java application to carry out additions and subtractions for numbers of any length. A number is represented as an object which includes a sign and two strings for the whole and decimal parts of the number.

  Display student details and classes in applet

Display student details and classes they have enrolled in Applet. The Applet should have following features. Update and View.

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