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
Nơi nào có điện tích thì xung quanh điện tích đó có :
maksim [4K]

Explanation:

sory sorry sorry sorrysorrysorry

4 0
2 years ago
How is a disc brake system different from a drum brake system? Short answer
ddd [48]

Answer:

Disc brake system use a slim rotor and small caliper to halt wheel movement but a drum brake system allow heat to build up inside the drum during heavy braking .

6 0
2 years ago
Read 2 more answers
DRIVERS ED
forsale [732]

Answer:

b

Explanation:

only if there signal is turned on

8 0
3 years ago
Read 2 more answers
Water at atmospheric pressure boils on the surface of a large horizontal copper tube. The heat flux is 90% of the critical value
masya89 [10]

Answer:

The tube surface temperature immediately after installation is 120.4°C and after prolonged service is 110.8°C

Explanation:

The properties of water at 100°C and 1 atm are:

pL = 957.9 kg/m³

pV = 0.596 kg/m³

ΔHL = 2257 kJ/kg

CpL = 4.217 kJ/kg K

uL = 279x10⁻⁶Ns/m²

KL = 0.68 W/m K

σ = 58.9x10³N/m

When the water boils on the surface its heat flux is:

q=0.149h_{fg} \rho _{v} (\frac{\sigma (\rho _{L}-\rho _{v})}{\rho _{v}^{2} }  )^{1/4} =0.149*2257*0.596*(\frac{58.9x10^{-3}*(957.9-0.596) }{0.596^{2} } )^{1/4} =18703.42W/m^{2}

For copper-water, the properties are:

Cfg = 0.0128

The heat flux is:

qn = 0.9 * 18703.42 = 16833.078 W/m²

q_{n} =uK(\frac{g(\rho_{L}-\rho _{v})     }{\sigma })^{1/2} (\frac{c_{pL}*deltaT }{c_{fg}h_{fg}Pr  } \\16833.078=279x10^{-6} *2257x10^{3} (\frac{9.8*(957.9-0.596)}{0.596} )^{1/2} *(\frac{4.127x10^{3}*delta-T }{0.0128*2257x10^{3}*1.76 } )^{3} \\delta-T=20.4

The tube surface temperature immediately after installation is:

Tinst = 100 + 20.4 = 120.4°C

For rough surfaces, Cfg = 0.0068. Using the same equation:

ΔT = 10.8°C

The tube surface temperature after prolonged service is:

Tprolo = 100 + 10.8 = 110.8°C

8 0
3 years ago
The total floor area of a building, including below-grade space but excluding unenclosed areas, measured from the exterior of th
alex41 [277]

Answer:

Gross building area

Explanation:

The Gross building area refers to the entire area of a building covering all the floors. The measurement is expressed in square feet. The Gross building area also includes basements, penthouses, and mezzanines. It is calculated by estimating the exterior dimension of the building. Storage rooms, laundries, staircases are also a part of the gross building area.

6 0
3 years ago
Other questions:
  • According to information found in an old hydraulies book, the energy loss per unit weight of fluid flowing through a nozzle conn
    6·1 answer
  • Are ocean currents always cold
    10·1 answer
  • Water (cp = 4180 J/kg·°C) enters the 2.5 cm internal diameter tube of a double-pipe counter-flow heat exchanger at 17°C at a rat
    7·1 answer
  • DO NOW: Name the three main legal categories of ownership.
    12·1 answer
  • Tests reveal that a normal driver takes about 0.75 s before he orshecan react to a situation to avoid a collision. It takes abou
    11·1 answer
  • Turbine blades mounted to a rotating disc in a gas turbine engine are exposed to a gas stream that is at [infinity] = 1100°C and
    6·1 answer
  • A very large plate is placed equidistant between two vertical walls. The 10-mm spacing between the plate and each wall is filled
    11·1 answer
  • What is the following diagram called?
    15·1 answer
  • 1. In a series circuit the sum of all voltage drops produced by the loads in the circuit
    7·1 answer
  • At the beginning of last year, tarind corporation budgeted $1,000,000 of fixed manufacturing overhead and chose a denominator le
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!