Concurrent Programming, JAVA Programming

Assignment Help:
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-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.
1
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-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 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.

Related Discussions:- Concurrent Programming

I am requiring webcam software integrated into my site, I am requiring webc...

I am requiring webcam software integrated into my site I have website and I am wanting webcam software integrated into my site the company I have found doesn't offer support in

Describe exception handling in java, Question A What are the difference be...

Question A What are the difference between an interface and an abstract class? Question B Describe Exception Handling in JAVA Question C Describe the following with resp

Explain any five buzz words in java, Question 1 Explain any five buzz w...

Question 1 Explain any five buzz words in Java 2 Explain exception classes and also explain common exceptions in java 3 Explain primitive and abstract data type in java

How to write exception subclasses, How to Write Exception Subclasses ? ...

How to Write Exception Subclasses ? Most exception subclasses inherit all their functionality from the superclass. Each subclass majorly serves as a marker for a various types

Design a game in java, Ten pigs were all in a pen, enjoying their morning s...

Ten pigs were all in a pen, enjoying their morning slop when a bird flew down from a nearby tree and began picking all the best bits out from the trough. This greatly perturbed the

Explain primitive and abstract data type in java, Question 1 Describe any ...

Question 1 Describe any five buzz words in Java Question 2 Describe exception classes and also explain common exceptions in java Question 3  Describe primitive and

Write code in javascript to display the odd numbers, Write code in JavaScri...

Write code in JavaScript to display the odd numbers among 20 to 100 using FOR statement? Note: No required to write whole HTML program. Just JavaScript code of require elemen

What system.out.println() signifies, What 'System.out.println()' signifies?...

What 'System.out.println()' signifies? 'System' is a predefined class. System class gives access to the system. 'out' is the output stream. 'println' is printin

What are the components of struts, Struts components can be classify into M...

Struts components can be classify into Model, View and Controller: ? Model: Components like business logic /business processes and data are the type of model. ? View: HTML, J

Write Your Message!

Captcha
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