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
Give five general principles involved in the process of sewage filtration?​
aleksandr82 [10.1K]

Answer:

Some general principles are given below in the explanation segment.

Explanation:

Sewage treatment seems to be a method to extract pollutants from untreated sewage, consisting primarily of domestic sewage including some solid wastes.

<u>The principles are given below:</u>

  • Unless the components throughout the flow stream become greater than the ports or even the gaps throughout the filter layer, those holes would be filled as either a result of economic detection.
  • The much more common element of filtration would be the use of gravity to extract a combination.
  • Broadcast interception or interference.  
  • Inertial influence.
  • Sieving seems to be an excellent method to distinguish particulates.

8 0
3 years ago
Explain how potential energy converts to kinetic energy in the loop-the-loop section of the roller coaster. Make sure to note wh
larisa86 [58]

Answer:

lol

Explanation:

8 0
3 years ago
A 0.19-m3 rigid tank equipped with a pressure regulator contains steam at 2 MPa and 300°C. The steam in the tank is now heated.
AVprozaik [17]

Answer:

576.21kJ

Explanation:

#We know that:

The balance mass m_{in}+m_{out}=\bigtriangleup m_{system}

so, m_e=m_1-m_2

Energy \ Balance\\E_{in}-E_{out}=\bigtriangleup E_{system}\\\\\therefore Q_i_n+m_eh_e=m_2u_2-m_1u_1

#Also, given the properties of water as;

(P_1=2Mpa,T_1=300\textdegree C)->v_1=0.12551m^3/kg,u_1=2773.2kJ/kg->h_1=3024.2kJ/kg\\\\(P_2=2Mpa,T_1=500\textdegree C)->v_2=0.17568m^3/kg,u_1=3116.9kJ/kg->h_1=3468.3kJ/kg

#We assume constant properties for the steam at average temperatures:h_e=\approx(h_1+h_2)/2

#Replace known values in the equation above;h_e=(3024.2+3468.3)/2=3246.25kJ/kg\\\\m_1=V_1/v_1=0.19m^3/(0.12551m^3/kg)=1.5138kg\\\\m_2=V_2/v_2=0.19m^3/(0.17568m^3/kg)=1.0815kg

#Using the mass and energy balance relations;

m_e=m_1-m_2\\\\m_e=1.5138-1.0815\\\\m_e=0.4323kg

#We have Q_i_n+m_eh_e=m_2u_2-m_1u_1: we replace the known values in the equation as;

Q_i_n+m_eh_e=m_2u_2-m_1u_1\\\\Q_i_n=0.4323kg\times3246.2kJ/kg+1.0815kg\times3116.9-1.5138kg\times2773.2kJ/kg\\\\Q_i_n=573.21kJ

#Hence,the amount of heat transferred when the steam temperature reaches 500°C is 576.21kJ

5 0
3 years ago
Select the correct answer. Jennifer, a construction manager at a construction firm, has to hire several contractors and subcontr
Ymorist [56]
A. Quality management
7 0
3 years ago
Read 2 more answers
A fluid of density 900 kg/m3 passes through a converging section of an upstream diameter of 50 mm and a downstream diameter of 2
NISA [10]

Answer:

Q= 4.6 × 10⁻³ m³/s

actual velocity will be equal to 8.39 m/s

Explanation:

density of fluid = 900 kg/m³

d₁ = 0.025 m

d₂ = 0.05 m

Δ P = -40 k N/m²

C v = 0.89

using energy equation

\dfrac{P_1}{\gamma}+\dfrac{v_1^2}{2g} = \dfrac{P_2}{\gamma}+\dfrac{v_2^2}{2g}\\\dfrac{P_1-P_2}{\gamma}=\dfrac{v_2^2-v_1^2}{2g}\\\dfrac{-40\times 10^3\times 2}{900}=v_2^2-v_1^2

under ideal condition v₁² = 0

v₂² = 88.88

v₂ = 9.43 m/s

hence discharge at downstream will be

Q = Av

Q = \dfrac{\pi}{4}d_1^2 \times v

Q = \dfrac{\pi}{4}0.025^2 \times 9.43

Q= 4.6 × 10⁻³ m³/s

we know that

C_v =\dfrac{actual\ velocity}{theoretical\ velocity }\\0.89 =\dfrac{actual\ velocity}{9.43}\\actual\ velocity = 8.39m/s

hence , actual velocity will be equal to 8.39 m/s

6 0
3 years ago
Other questions:
  • What is the difference between absolute and gage pressure?
    11·1 answer
  • A teenager was pulling a prank and placed a large stuffed penguin in the middle of a roadway. A driver is traveling on this leve
    13·1 answer
  • Project 8:The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exe
    5·1 answer
  • How many grams of perchloric acid, HClO4, are contained in 37.6 g of 70.5 wt% aqueous perchloric acid? How many grams of water a
    10·1 answer
  • When trying to solve a frame problem it will typically be necessary to draw many free body diagrams. a)-True b)-False
    6·1 answer
  • All of the following are categories for clutch covers except
    11·1 answer
  • An engine jack is used to lift a 265-lb engine 6'. How much work, in ft-lb, is performed?
    11·1 answer
  • Why are there few effective HCI standards?
    6·1 answer
  • Drag each label to the correct location on the chart. Classify the organisms based on how they obtain food.
    14·2 answers
  • Technician A says that acid core solder should be used whenever aluminum wires are to be soldered.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!