1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nikitich [7]
3 years ago
5

A single-lane bridge connects the two Vermont villages of North Tunbridge and South Tunbridge. Farmers in the two villages use t

his bridge to deliver their produce to the neighboring town. The bridge can become deadlocked of a northbound and a southbound farmer get on the bridge at the same time. (Vermont farmers are stubborn and are unable to back up.)a. Using exactly one semaphore, design an algorithm that prevents deadlock. Do not be
concerned about starvation and inefficency.

b. Provide a solution using Monitor that is starvation-free.

Engineering
1 answer:
Naddika [18.5K]3 years ago
4 0

Answer:

Check the explanation

Explanation:

Main1.java

import java.lang.InterruptedException;

import java.lang.Thread;

import java.util.Random;

public class Main {

final private static int FARMERS = 10;

public static void main(String[] args) {

Bridge bridge = new Bridge();

Random r = new Random();

System.out.println("Running with " + FARMERS + " farmers...");

// Enter a bunch of farmers from different directions.

for (int i = 0; i < FARMERS; i++) {

Farmer farmer;

if (r.nextBoolean()) {

farmer = new SouthBoundFarmer(bridge);

} else {

farmer = new NorthBoundFarmer(bridge);

}

cross(farmer);

}

}

private static void cross(Farmer f) {

new Thread(f).start();

}

}

SouthBoundFarmer.java

public class SouthBoundFarmer extends Farmer {

public SouthBoundFarmer(Bridge b) {

super(b);

this.name = "South";

}

}

Farmer.java

import java.lang.InterruptedException;

import java.util.Random;

public class Farmer implements Runnable {

private Bridge bridge;

private Random random;

protected String name;

public Farmer(Bridge b) {

this.bridge = b;

this.random = new Random();

}

public void crossBridge(Bridge bridge) {

System.out.println("[" + this.name + "] Waiting to enter bridge...");

try {

bridge.enter();

System.out.println("[" + this.name + "] Entering bridge...");

// Crossing bridge...some farmers are fast, others are slow :P

Thread.sleep(1000 + random.nextInt(9000));

System.out.println("[" + this.name + "] Leaving bridge...");

} catch (InterruptedException e) {

System.out.println("...Interrupted!");

} finally {

bridge.leave();

}

}

public void run() {

this.crossBridge(this.bridge);

}

}

Bridge.java

import java.lang.InterruptedException;

import java.util.concurrent.Semaphore;

public class Bridge {

private Semaphore lock;

public Bridge() {

this.lock = new Semaphore(1);

}

public void enter() throws InterruptedException {

this.lock.acquire();

}

public void leave() {

this.lock.release();

}

}

NorthBoundFarmer.java

public class NorthBoundFarmer extends Farmer {

public NorthBoundFarmer(Bridge b) {

super(b);

this.name = "North";

}

}

KINDLY CHECK THE OUTPUT BELOW :

You might be interested in
What is a ton of refrigeration?
AURORKA [14]

Explanation:

The unit refrigeration is generally is given in terms of tons.In refrigeration compressor consume some amount of work to produce the cooling effect  with the help of evaporator and condenser.

In the simple words ton is the cooling load of refrigeration system.

So  

1 ton = 3.5 KW

1 ton = 12,000 BTU/hr

 

6 0
3 years ago
The ________ is the part of the drill press that holds and rotates the cutting tool.
lana66690 [7]

Answer:

Spindle

Explanation:

Please mark me brainliest

8 0
3 years ago
Read 2 more answers
​Write 83,120 in expanded form using powers of 10.
maksim [4K]

Answer:

8*10000+3*1000+1*00+2*10+2

Explanation:

8 0
2 years ago
Visual perception is a mental process that is non selective<br> True<br> False
NARA [144]

The statement "Visual perception is a mental process that is non selective" is false, it is a psychic function that allows the organism to capture, elaborate and interpret selective information that comes from the environment.

<h2>What is visual perception?</h2>

Visual perception is that inner sensation of apparent knowledge, resulting from a specific stimulus or light impression recorded by the eyes.

<h3>Characteristics of visual perception</h3>

  • It incorporates the sensory stimuli received from objects, situations or events and converts them into a meaningful interpretation experience.

  • It is an active process of the brain through which an external reality is created by transforming the light information captured by the eye.

Therefore, we can conclude that visual perception is the interpretation made by the brain of the different organisms of the stimuli received through the senses.

Learn more about visual perception here: brainly.com/question/10259599

3 0
2 years ago
a cubical box 20-cm on a side is contructed from 1.2 cm thick concrete panels. A 100-W light bulb is sealed inside the box. What
Flura [38]

Answer:

Temperature on the inside ofthe box

Explanation:

The power of the light bulb is the rate of heat conduction of the bulb, dq/dt = 100 W

The thickness of the wall, L = 1.2 cm = 0.012m

Length of the cube's side, x = 20cm = 0.2 m

The area of the cubical box, A = 6x²

A = 6 * 0.2² = 6 * 0.04

A = 0.24 m²

Temperature of the surrounding, T_0 = 20^0 C = 273 + 20 = 293 K

Temperature of the inside of the box, T_{in} = ?

Coefficient of thermal conductivity, k = 0.8 W/m-K

The formula for the rate of heat conduction is given by:

dq/dt = \frac{kA(T_{in} - T_0)}{L} \\\\100 = \frac{0.8*0.24(T_{in} - 293)}{0.012}\\\\T_{in} - 293 = \frac{100 * 0.012}{0.8*0.24} \\\\T_{in} - 293 = 6.25\\\\T_{in} = 293 + 6.25\\\\T_{in} = 299.25 K\\\\T_{in} = 299.25 - 273\\\\T_{in} = 26.25^0 C

5 0
3 years ago
Other questions:
  • What are the four processes of the Carnot cycle? Sketch the Carnot cycle (a) on T-s (temperature - entropy) and P-V (pressure -
    7·1 answer
  • Carbon dioxide flows at a rate of 1.5 ft3 /s from a 3-in. pipe in which the pressure and temperature are 20 psi (gage) and 120 °
    8·1 answer
  • A waste treatment pond is 50m long and 25m wide, and has an average depth of 2m.The density of the waste is 75.3 lbm/ft3. Calcul
    12·1 answer
  • (d) Suppose two students are memorizing a list according to the same model dL dt = 0.5(1 − L) where L represents the fraction of
    6·1 answer
  • Air expands through a turbine operating at steady state. At the inlet p1 = 150 lbf/in^2, T1 = 1400R and at the exit p2 = 14.8 lb
    10·1 answer
  • The best way to identify common masonry problems is to call the engineer.<br> True or False
    6·1 answer
  • A horse pulls a cart along a road with a force of 550 lbs. If the horse does 2,674,100 ftlbs of work by the time it stops, how f
    9·2 answers
  • Problem 3.10 One/half million parts of a certain type are to be manufactured annually on dedicated production machines that run
    7·2 answers
  • 8th grade safety test
    9·1 answer
  • 8. What are used by the project architect to depict different building systems and to show how they correlate to one anothe
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!