Implement bounded partial queue by using signaling mechanism

Assignment Help JAVA Programming
Reference no: EM1376967

Problem A

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. getbalance() gives the current balance.

1. Implement this savings account using locks and conditions (use any of the Readers-Writers lock from chapter 8). 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.

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

1    void transfer(int k, Account reserve) {

2            lock.lock();

3            try {

4                  reserve.withdraw(k);

5                  deposit(k);

6            } finally lock.unlock();

7   }

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?

Problem B

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

2. Implement the same using a signaling mechanism that signals to all waiting dequeuers.

3. Do a performance comparison using timing analysis. Which works faster?

Reference no: EM1376967

Questions Cloud

Share resources on wins server : Client wants your friend's shop to log on to its WINS server so they can share resources more directly. With security in mind, what do you tell your friend to do? Why?
Presentation on a safety unit : Strat discussing, planning and researching a Safety Unit Presentation - work as a Safety Unit for an industrial company and create a strategy for implementing, maintaining,
What is mm capital structure theory : What is MM capital structure theory without taxes and bankruptcy costs and what is the break-even EBIT? How to find the break-even point?
Implementation of theoretical approach : Suppose you are a human services employer at a shelter for houseless women and their children. The targets of the shelter are to give food and shelter on a temporary basis to women & their children,
Implement bounded partial queue by using signaling mechanism : Implement the same using a signaling mechanism that signals to all waiting dequeuers and do a performance comparison using timing analysis. Which works faster?
Payment to an employment agency : Nextel South Corporation, a communications company, contacted R.A. Clark Consulting, Ltd., an executive search firm, about finding an employment manager for Nextel's call center in Atlanta, Georgia.
Discussion on statute of frauds : Damon, for consideration, orally make promise to pay Gary $300 a month for as long as Gary lived, with payments to be made on the 1st day of every month.
Discussion on bay city health : Bay City Health is a nonprofit, community based, healthcare delivery network in Providence, Rhode Island. The network includes two acute-care hospitals, a network of more than eight hundred physicians,
Construct a decision tree to help expando : Calculate the EMVs for each of the three alternatives. For each alternative, please include at least one step of calculation and the correct answer for full credit.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Determine if strings are equal

Complete the recursive method match in the code below which will determine whether or not two strings match.

  Java-s ability to derive new fonts from existing ones

Find out where on your system these font libraries are located. When you do, please specify the operating system and the location (folder/directory) where you found them. Discuss Java's ability to derive new fonts from existing ones.

  List various bindings that are needed to determine semantics

List the various bindings that are required to determine the semantics when the statement is executed. For each binding, indicate the binding time used for the language.

  Program to find maximum-minimum of sequence of values

Common task which should be done in loop is to find maximum and minimum of sequence of values. File Temps.java contains program which reads in sequence of hourly temperature readings over 24- hour period.

  Write an interface for an abstract method

Write an interface, PointingDevice, containing:  an abstract method, getXCoord that returns an int and an abstract method, getYCoord that returns an int.

  Can linear search algorithm be encoded using recursion

Determine the average amount of time people spend waiting for tables and provide examples from the "real world" of unsorted lists, sorted lists, indexed lists, lists that permit duplicate elements, and lists that do not permit duplicate elements

  Uml exercise

UML Exercise: Automated Teller Machine (ATM),   1. To allow authorized card holders to make transactions,   Brief Summary of Requirements:

  Implementation the two classes

Program Specifications: In the new implementation, the two classes, Student and Grades, are defined with the following operations/methods.

  Robot preparing for competition

Create an event so that the skateboard can be controlled by game player

  Define private instance variable to hold boolean value

Write a Java Enumeration "LetterGrade" that represents letter grades A through F including plus and minus grades. Define a private instance variable to hold a boolean value.

  Modeling the caves

Assignment 2 Description:  You are a mighty warrior, and armed with your trusty bow and 3 arrows, you enter The Caves in search of the mighty Wumpus. If you shoot the Wumpus, you are victorious and the masses will praise you, but if you stumble upon ..

  Compilation and Execution - JAVA problem

Style marks are based on how your submitted code looks. Remember that good code is easily readable (and understandable) by someone who did not write it. For assignments, you should also include your name, student number, what course this is, what ass..

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