answer.
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]
2 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]2 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
Who want to play "1v1 lol unblocked games 76"
kotegsom [21]

Answer:I want to play what game?

Explanation:

3 0
2 years ago
Read 2 more answers
A three-point bending test was performed on an aluminum oxide specimen having a circular cross section of radius 3.5 mm (0.14 in
RideAnS [48]

To resolve this problem we have,

R=3.5mm\\F_f1=950N\\L_1=50mm\\b=12mm\\L_2=40mm

F_{f2} is unknown.

With these dates we can calculate the Flexural strenght of the specimen,

\sigma{fs}=\frac{F_{f1}L}{\pi R^3}\\\sigma{fs}=\frac{(950)(50*10^{-3})}{\pi 3.5*10^{-3}}\\\sigma{fs}=352.65Mpa

After that, we can calculate the flexural strenght for the square cross section using the previously value.

\sigma{fs}=\frac{F_{f2}L}{\pi R^3}\\(352.65*10^6)=\frac{3Ff(40*10^{-3})}{2(12*10^{-10})}\\F_{f2}=\frac{352.65*10^6}{34722.22}\\F_{f2}=10156.32N\\F_{f2}=10.2kN

6 0
2 years ago
referring to either the CMS file or code book index, what is the cross reference for reduction of a dislocation?
Oksi-84 [34.3K]

Answer:

reposition

Explanation:

if you go to your icd 10 pcs index located on page 1 then  look up reduction the subterm is of a dislocation which leads you to the answer reposition

4 0
2 years ago
A 227 pound compressor is supported by four legs that contact the floor of a machine shop. At the bottom of each leg there is a
Ganezh [65]

Answer:

1.312 in

Explanation:

Data provided in the question:

Weight of the compressor, W = 227 pound

Number of legs = 4

Maximum pressure = 42 psi

Now,

Let F be the force taken by the legs

Therefore,

W = 4F

or

227 pound = 4F

or

F = 56.75 pounds

Also,

Force = Pressure × Area

or

56.75 pounds = 42 psi × πr²                      [ r is the diameter of one leg]

or

r² = 0.4301

or

r = 0.656

therefore,

diameter = 2r = 2 × 0.656

= 1.312 in

6 0
2 years ago
(a) If 15 kW of power from a heat reservoir at 500 K is input into a heat engine with an efficiency of 37%, what is the power ou
julsineya [31]

Answer:

(A) Power output will be 5.55 KW (b) lower temperature will be 315 K

Explanation:

We have given efficiency of heat engine \eta =37% = 0.37

Input power = 15 KW

Temperature of heat reservoir T_H=500K

(A) We know that \eta =\frac{output}{input}

So  [text]0.37=\frac{output}{15}[text]

Output = 5.55 KW

(B) We also know that [text]\eta =1-\frac{T_L}{T_H}0.37=\frac{output}{15}[text], here T_L  is lower temperature and T_H is higher temperature

So 0.37=1-\frac{T_L}{T_H}

0.37=1-\frac{T_L}{500}

T_L=315K

5 0
2 years ago
Other questions:
  • A 1020 CD steel shaft is to transmit 15 kW while rotating at 1750 rpm. Determine the minimum diameter for the shaft to provide a
    10·1 answer
  • a. Replacing standard incandescent lightbulbs with energy-efficient compact fluorescent lightbulbs can save a lot of energy. Cal
    9·1 answer
  • Consider a normal shock wave in air. The upstream conditions are given by M1=3, p1 = 1 atm, and r1 = 1.23 kg/m3. Calculate the d
    15·1 answer
  • The driving force for fluid flow is the pressure difference, and a pump operates by raising the pressure of a fluid (by converti
    13·1 answer
  • The following passage contains a fragment. Select the correct revision. Presley took the exuberance of gospel and added the freq
    7·1 answer
  • In this module you learned about searching, sorting and algorithms in C++ and how to implement these elements in your C++ progra
    6·1 answer
  • A commercial refrigerator with refrigerant-134a as the working fluid is used to keep the refrigerated space at -30C by rejecting
    13·1 answer
  • Solid spherical particles having a diameter of 0.090 mm and a density of 2002 kg/m3 are settling in a solution of water at 26.7C
    8·1 answer
  • Discuss your interpretation of the confidence-precision trade-off, and provide a few examples of how you might make a choice in
    14·1 answer
  • A fuel oil is burned with air in a furnace. The combustion produces 813 kW of thermal energy, of which 65% is transferred as hea
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!