Implement bounded partial queue using signaling mechanism

Assignment Help JAVA Programming
Reference no: EM13706040

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 until the balance becomes k or greater. getbalance() gives the current balance.

1. Implement this savings account using locks and conditions (use java.util.concurrent.locks.ReentrantLock). 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-queu e 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 foo() followed by bar().

We want to add synchronization to ensure that no thread starts executing bar() until all threads have finished executing foo(). To achieve this, we will insert some barrier code between the two methods. Implement the following two schemes for barrier code:

Use a shared counter protected by test-an d-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 barrier, it sets b[0] to 1, and repeatedly reads b[n - 1] 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 foo() 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: EM13706040

Questions Cloud

Establish authorities and responsibilities for database : 1. Establish authorities and responsibilities for database security management. 2. Develop operational and incident management procedures when security breaches are discovered. 3. Define personnel and procedures for daily administration and maintenan..
Financial plan for the capstone project : Students will create a strategic business plan for their culminating project in BUS-485. The structure of this assignment is comprehensive and integrative. It requires synthesis and evaluation of information, skills, and knowledge developed thr..
The news that involves two or more cultures : 1.Select a situation that is currently in the news that involves two or more cultures. Analyze the situation using Hofstede's original four dimensions, plus the universalism/particularism and task/relationship dimensions.
Keep a competitive edge on the marketplace : While information systems has one meaning, it can be used in different ways for companies to keep a competitive edge on the marketplace. Compare and Contrast two distinctly different organizations on how they use information systems in their or..
Implement bounded partial queue using signaling mechanism : Can you explain the reason? You can run the experiments on ecen5033.colorado.edu. Submit the code as well as experimental results - Implement both these schemes in Java. Each of the methods foo() and bar() just sleeps for 20 milliseconds.
Some typical production organizations : 1. Discuss your thoughts concerning some of the different types of inventories found within some typical production organizations (Raw Materials, Work In Process, Finished Goods, Transit Inventory, Buffer Stocks, Anticipation, Decoupling).
The button also contained the phrases : In late July 1990, Wilson, a Roman Catholic, made a religious vow that she would wear an antiabortion button "until there was an end to abortion or until she could no longer fight the fight." The button was two inches in diameter and showed a c..
Find the optimized solution to reach destination : The robot has the map of Romania with additional information given in the picture. Using A* Intelligent search how the robot will find the optimized solution to reach destination?
Rachel planned to open a pastry shop in a resort town : Rachel planned to open a pastry shop in a resort town on the east coast.  As she pondered her organizational set-up, she decided she would need four employees to specialize in the creation and production of delicate pastries, and three employe..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Rationale for declaring an array of objects of the class

Explain the dimension of the array and why you chose that number of elements for the object array.Can you give the answer ASAP?

  Information systems to strengthen customer

Which of the following illustrates the use of information systems to strengthen customer and supplier intimacy? BPM is considered concluded when the new processes are both implemented and accepted.

  The objective is to implement a menu-based system for bank

the objective is to implement a menu-based system for bank accounts in order to simulate a very simple banking system.

  What is the minimal total weight of cylinders

A scuba diver uses a special equipment for diving. He has a cylinder with two containers: one with oxygen and the other with nitrogen. Depending on the time he wants to stay under water and the depth of diving the scuba diver needs various amount of ..

  Create a class called employee with name idno address and

create a class called employee with name idno address and phone number as attributes. create the setter and getter

  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.

  Display a table of values

Using Netbeans, use repetition to display a table of values showing x, the square of x and the cube of x. X is to go up to 5.

  Approximate the volume of cheese in a rectangular hunk

You will create a program that will approximate the volume of cheese in a rectangular hunk of Swiss cheese. For this approximation you will assume that the holes in the Swiss cheese are of two types: spherical bubbles (all of the same size) or cyl..

  Calculate the optimal position of the large pipeline

Your task is to calculate the optimal position (on the y-axis) of the large pipeline, so that the total length of all smaller pipelines is shortest

  Discussion htmlcssjavascript placementnbspplease respond to

discussion htmlcssjavascript placementnbspplease respond to the followingcompare and contrast the process of adding

  Recursive method

What will happen when the following recursive method is executed with an initial input value of 10?public int recursiveMethod(int input)

  Java program use breadth-first search closest broadcast

Write the java program which will use breadth-first search (which you implement as part of your program) to determine the closest broadcast vertex for each vertex in graph.

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