Computer Science, asked by m97hassan, 10 months ago

Write a java program to provide the synchronization required for controlling the access of a couple of a pedestrian bridge. the bridges are used to cross a dangerous, infected crocodile river. the picture in the attachment illustrates the problem

Assume that you have a function called CrossBridge(n) already given to you. You don’t know how long it takes to execute. This function causes the person process to cross bridge n (which can have valid values of I or 2).

A person starting on the at shore will end up on the east shore A person starting on the west shore will end up on the east shore. This function returns when the action is completed.
• Use a monitor as the synchronization mechanism for your solution.
• Each person is represented as a thread executing a Person () function. Assume that all person threads (many of them} are already initialized and started, and that they arrive randomly
• Write the Person () function which will be called by people wanting to cross the bridge.
• Write any additional functions that you need for the monitor

Your solution must obey the following rules:
I. Each bridge is strong enough to hold only one-person time. Additional people will break the bridge and they all will fall in the river and be attacked by the crocodiles.
2.If there is more than one person wanting to cross the river, both bridges should be used at the same time.
3. People should get to use the bridge in approximately the same order in which they arrived.
4. Initially, both bridges are unoccupied.
5.You cannot use busy waiting.
Hint: the person () function is probably not in the monitor class. You might consider having this function call functions in a “BridgeControl “monitor class with a condition variable.

Public class Nile {
//The Person function -write the code here
Public void person () {
}
Class monitor BridgeControl {
//write the private monitor fields
//write the public monitor methods
}

Attachments:

Answers

Answered by Anonymous
6

Answer:

it is a Java Program at class monitor Bridge control at the private monitor fields in the public monitor methods

Similar questions