Comp2240comp6240 - operating systems assignment - using


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

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Comp2240comp6240 - operating systems assignment - using
Reference No:- TGS02928944

Expected delivery within 24 Hours