Design and implement an algorithm that prevents deadlock

Assignment Help JAVA Programming
Reference no: EM132135493

Operating Systems Assignment -

Problem 1: Sharing the Bridge

A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge to deliver produce to the other island, return back to their island and this is repeated indefinitely. It takes a farmer carrying produce 20 steps to cross the bridge. Once a farmer (say a North Island farmer identified as N_Farmer1) crosses the bridge (from North Island to South Island) he just attempts to cross the bridge in the opposite direction (from South Island to North Island) and so on. Note that the ID of the farmer does NOT change.

The bridge can become deadlocked if a northbound and a southbound farmer are on the bridge at the same time (New Zealand farmers are stubborn and will not back up). The bridge has a large neon sign above it indicating the number of farmers that have crossed it in either direction. The neon sign counts multiple crossing by the same farmer.

Using semaphores, design and implement an algorithm that prevents deadlock. Use threads to simulate multiple/concurrent farmers and assume that the stream of farmers are constantly attempting to use the bridge from either direction. Your program should input parameters at runtime to initialise the number of farmers from each direction. For example [N=5, S=5] would indicate a constant stream of 5 farmers from each direction wanting to use the bridge. You also make sure that the solution is starvation-free (the situation in which northbound farmers prevent southbound farmers from using the bridge, or vice versa should not occur).

Problem 2: Ice-cream time

A new ice-cream parlour has been opened at Shortland Student Hub. The parlour does not offer take away service but there is only five seats in the parlour to eat in. A customer may arrive to the parlour at any time and may take a certain time to finish his ice-cream. The manager chooses a peculiar rule to serve his customers. If a customer arrives when there is an empty seat, then the customer can immediately take a seat. However, if all the five seats are occupied (i.e. there are five customers enjoying their ice-creams at any instant) then all the arriving customers have to wait for the entire party (all current customers) to leave before they can get their seats.

Using semaphores design and implement an algorithm that manages the customers entering and leaving the ice-cream parlour in line with manager's rules. Use threads to simulate multiple/concurrent customers. Your solution must be fair - starvation free. Assume no time is wasted in taking seat, serving/starting eating ice-cream and leaving the parlour.

Problem 3: Hot or Iced Coffee?

School of EEC, UoN bought a coffee machine that can serve both iced and hot coffee for the staffs. The coffee machine has three dispensing heads which can serve three clients (staffs) in parallel. We call a staff Hot Client (H) if (s)he is looking for hot coffee and a Cold Client (C) if (s)he is looking for cold coffee. However, the machine can operate in either of its two modes (hot or cold drink) at a time. If a Hot Client has started to make coffee in the machine then the other two vacant dispersers can serve hot coffee only - a Cold Client must wait. A client (Hot or Cold) can choose the brew strength by choosing the brew time at the beginning. So the assumptions in operating the coffee machine are

  • Hot and Cold clients cannot use the machine at the same time.
  • No more than three clients can use the machine simultaneously.
  • Each client can choose different time to brew his coffee.

Using monitor, design and implement an algorithm that ensures the operation of the coffee machine according to the above characteristics. Use threads to simulate multiple/concurrent clients. Your solution should be fair - stream of Hot Clients should not prevent a Cold Client from using the coffee machine or vice versa. A Hot Client with ID y (i.e. Hy) should not be served before a HOT Client with ID x (i.e. Hx) where x < y. And the same for the cold clients.

Programming Language: The preferred programming language is Java.

If you wish to use any language other than the preferred programming language, you must first notify the course demonstrator.

User Interface: There are no marks allocated for using or not using a GUI - the choice is yours.

Input and Output: Your program should accept data from an input file of name specified either as a command line argument (for non-GUI solutions) or using a file dialogue (for GUI solutions). The sample inputs are shown above to demonstrate the expected formatting for inputs. Your submission will be tested with the above data and with other input files.

Your program should output to standard output (for non-GUI solutions) or to a text area (for GUI solutions). Output should be strictly in the shown output format.

Attachment:- Assignment File.rar

Reference no: EM132135493

Questions Cloud

In the goals and unethical behavior article : In the goals and unethical behavior article, the authors found unethical behavior to be most likely when subjects were _______ reaching their goal
The lived experience of confucianism and islam : These assignments are based upon required course readings that proffer contemporary accounts of the lived experience of "Confucianism and Islam".
How do you listen to the music : Write a paper detailing your experience of this music. Of the various musical elements discussed in class (melody, harmony, rhythm, timbre, texture, dynamics).
Importance on disaster recovery : Explain why some organizations may not place enough importance on disaster recovery. What might happen to these organizations in the event of an actual disaster
Design and implement an algorithm that prevents deadlock : COMP2240/COMP6240 - Operating Systems Assignment - Using semaphores, design and implement an algorithm that prevents deadlock
Does the christian or muslim view of the human person : Does the Christian or Muslim view of the human person and the role in their salvation make more sense? Why?
Covered under commercial general liability policy : Define and describe the different types of liability risks covered under a commercial general liability policy.
Identify three of the organization key publics : Select a local small business and write a brief analysis of its function and the issues routinely faced. Identify three of the organization's key publics.
What are the appropriate boundaries : Just like a song has a melody around which everything else revolves, so does a reading passage. The melody of a reading is called the main idea.

Reviews

len2135493

10/9/2018 1:37:44 AM

Deliverable: For each problem, the program source code and a README file containing any special instructions required to compile and run the source code. If programmed in Java, your main class should be c9999999A2Px (where c9999999 is your student number, A2 for assignment 2 and Px is the problem number i.e. P1, P2 or P3) i.e. your program for the first problem can be executed by running “java c9999999A2P1”. If programming in other languages, your code should compile to an executable named “c9999999A2Px”.

len2135493

10/9/2018 1:37:40 AM

Brief 1 page (A4) review (report = 10%) of the how you tested your programs to ensure they enforced mutual exclusion and are deadlock and starvation free. Please place all files and the README file for each problem in a separate folder. There should be three folders for the solutions of three problems. Submit all folders, files and the 1 page report plus a copy of the official assignment cover sheet in a ZIPPED folder through Blackboard. The folder name should be “c9999999A2” and the zip file should be name as c9999999A2.zip (where c9999999 is your student number). NOTE: Assignments submitted after the deadline (11:59 pm Friday 12th October 2018) will have the maximum marks available reduced by 10% per 24 hours. NOTE: For the same input the output may look somewhat different from run to run.

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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