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

  Design the required data structures using uml class diagrams

Analyse the given problem, model, and design the required data structures using UML class diagrams. You will be implementing the software solution

  Describe dma transfer

Describe DMA transfer

  How is dynamic security assessment software used

How is dynamic security assessment (DSA) software used in actual power system operations - what techniques are used to decrease the time required to solve the DSA problem?

  Write a function to decode the original text

If you erase lower two bits in the red value, you can clear space for hiding values 0-4. Write a function to decode the original text.

  Describe one application relevant for ig based energy system

IGs need dc-ac, ac-dc, and ac-ac converters. Describe one application, relevant for IG-based energy system, for each of those power conversions.

  Discuss have you identified an operating system

Have you identified an operating system that is more suitable in the given scenario

  How many total bits will you transmit

How many total bits will you transmit using asynchronous transmission? How many total bits will you transmit using synchronous transmission?

  Write a program that uses a two-dimensional array

Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year.

  What is the difference between a transition and an animation

What is the difference between a transition and an animation? What is a selector, beginning attribute value selector, and end attribute value selector?

  Discuss different concepts presented in the articles

Discuss at least 3 different concepts presented in the articles. As an IT professional, how would you apply the three (3) concepts you identified.

  How to convert 2d array to 1d array

how to convert 2d array to 1d array for instance

  What may be the penalty for which crimes

What may be the penalty for which crimes. Who should enforce these laws?

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