Demonstrate that the algorithm works using two threads

Assignment Help Computer Engineering
Reference no: EM132200856

Write a java program for the following assignment.

Assignment:

Use threads to implement Peterson's algorithm for mutual exclusion. Demonstrate that the algorithm works using two threads. One of the threads should continually print "a".

The other thread should continually print "b". Each time a thread prints, it should update a character counter (which is protected using Peterson's algorithm).

After 30 characters have been printed, the thread that prints next should print a new line and reset the character counter to 0.

All access to the character counter should reside in a critical section protected by Peterson's algorithm. All code that does not require mutual exclusion should reside outside of critical sections.

Note: You must explicitly use threads. You must also explicitly implement Peterson's algorithm for mutual exclusion. Finding some language that implements threads, the algorithm (or general mutual exclusion), as a built-in function of some command/commands will not be acceptable.

Finally, you will write a report explaining your implementation and addressing the following question:

Does Peterson's Algorithm properly implement Mutual Exclusion of the critical code section?

Be sure to address each of the six requirements for Mutual Exclusion.

1. Mutual exclusion must be enforced: Only one process at a time is allowed into its critical section, among all processes that have critical sections for the same resource or shared object.

2. A process that halts in its noncritical section must do so without interfering with other processes.

3. It must not be possible for a process requiring access to a critical section to be delayed indefinitely: no deadlock or starvation.

4. When no process is in a critical section, any process that requests entry to its critical section must be permitted to enter without delay.

5. No assumptions are made about relative process speeds or number of processors.

6. A process remains inside its critical section for a finite time only.

Reference no: EM132200856

Questions Cloud

Write a program that reads ten characters into a linked list : Write a java program that reads ten characters into a linked list and displays them in the reverse of the order in which they were read.
Write a java program with two checkboxes : Write a Java program with two checkboxes, one labeled BLUE and the other labeled ORANGE.
Reverse the order of words and displays on the console : Write a Java program that reads a file, reverses the order of words and displays on the console. The words can be on the same or separate lines.
Display a list of distinct numbers in the input : Display a list of distinct numbers in the input and the occurrence of each distinct value.
Demonstrate that the algorithm works using two threads : Use threads to implement Peterson's algorithm for mutual exclusion. Demonstrate that the algorithm works using two threads.
Write a java program that creates a one-dimensional array : Write a JAVA Program that creates a one-dimensional array and fills it with the following numbers in this given order.
What role do portals play in : Are they still as relevant as they were a few years ago? More relevant? Support your conclusion with additional research on the web.
A program to calculate rectangular and right triangles : Write a java program that calculates of rectangular and right triangles. The main function then only outputs the areas of the two calculated areas.
Demonstrate deadlock without synchronized keywoord : Write a Java program that demonstrates deadlock WITHOUT synchronized keywoord.

Reviews

Write a Review

Computer Engineering Questions & Answers

  What would capacities and costs be to enable multiple PVCs

To do this, we'll need to run multiple PVCs through Chicago. Can this be done? If so, what would the capacities and costs be to enable this?

  What was the strategic benefit to microsoft of outsourcing

what was the strategic advantage to microsoft of outsourcing xbox production to flextronics?what were the risks

  Draw the array for every candidate swapping

Draw the array for every candidate swapping in every iteration separately. Mark the swapped elements and mark the iterations (steps).

  Ask the user for the value of four resistors in your series

The "main" section of the program will ask the user for the value of four resistors in your series circuit and the total voltage (V) applied to the series.

  Give a list of n distinct positive integers

Write for the following problem a recursive algorithm whose worst case time complexity is not worse than O(n ln n).

  Create a finite automata

Create a finite automata that takes only the words baa, ab and abb and noother strings longer or shorter

  What does the php function mysql-fetch-array do

What does the PHP function mysql_fetch_array do? Explain the exact form of the value returned by mysql_fetch_array.

  Create two essay questions and associated answers

Create two essay questions and associated answers. Wharton Managing Emerging Technologies - Technology Specialization and the Path of Emerging Technologies.

  Question1 write down a program with a function that returns

question1. write down a program with a function that returns a random integer between 0 and an integer supplied as an

  Develop applications involving complex component technology

Develop applications involving complex component technology. Design and implement technical solutions addressing connectivity between components.

  How will you use kill to ensure that a process is killed

How will you use kill to ensure that a process is killed? How will you kill the last background job without knowing its PID?

  Generate the two-dimensional string array

Declare and initialize the 2 dimensional array a b c d e f g h i Next print one diagonal of this "determinant" on one line.

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