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
At a point on the free surface of a stressed body, the normal stresses are 20 ksi (T) on a vertical plane and 30 ksi (C) on a ho
victus00 [196]

Answer:

The principal stresses are σp1 = 27 ksi, σp2 = -37 ksi and the shear stress is zero

Explanation:

The expression for the maximum shear stress is given:

\tau _{M} =\sqrt{(\frac{\sigma _{x}^{2}-\sigma _{y}^{2}  }{2})^{2}+\tau _{xy}^{2}    }

Where

σx = stress in vertical plane = 20 ksi

σy = stress in horizontal plane = -30 ksi

τM = 32 ksi

Replacing:

32=\sqrt{(\frac{20-(-30)}{2} )^{2} +\tau _{xy}^{2}  }

Solving for τxy:

τxy = ±19.98 ksi

The principal stress is:

\sigma _{x}+\sigma _{y} =\sigma _{p1}+\sigma _{p2}

Where

σp1 = 20 ksi

σp2 = -30 ksi

\sigma _{p1}  +\sigma _{p2}=-10 ksi (equation 1)

\tau _{M} =\frac{\sigma _{p1}-\sigma _{p2}}{2} \\\sigma _{p1}-\sigma _{p2}=2\tau _{M}\\\sigma _{p1}-\sigma _{p2}=32*2=64ksi equation 2

Solving both equations:

σp1 = 27 ksi

σp2 = -37 ksi

The shear stress on the vertical plane is zero

4 0
4 years ago
Which option best describes a way engineers can provide maintenance, diagnoses, upgrades, or duplicates even for products they d
guajiro [1.7K]

Answer:

Reverse Engineering

Explanation:

Just took the test

4 0
3 years ago
1.<br> se reception. It's<br> In remote areas, your GPS device<br> a good idea to have a _
marysya [2.9K]

GPS device  details are given below.

Explanation:

Even a simple GPS unit has a wide range of settings and features. Because every unit’s operation varies, this article won’t provide step-by-step details. Read the owner's manual to familiarize yourself with it.. If you’d like additional help, you can also sign up for a GPS navigation class at an REI store.

Though steps vary, all GPS receivers do the following basic functions:

Display position: A GPS tells you where you are by displaying your coordinates; it also shows your position on its base map or topo map.

Record tracks: When tracking is turned on, a GPS automatically lays down digital bread crumbs, called “track points,” at regular intervals. You use those later to retrace your steps or to evaluate the path you traveled.

Navigate point-to-point: A GPS directs you by giving you the direction and distance to a location, or “waypoint.” You can pre-mark waypoints by entering their coordinates at home. In the field you can have the unit mark a waypoint at a place you'd like to return to, such as the trailhead or your campsite. A GPS unit provides the bearing and distance “as the crow flies” to a waypoint. Because trails don’t follow a straight line, the bearing changes as you hike. The distance to travel also changes (decreasing, unless you’re heading the wrong direction) as you approach your goal.

Display trip data: This odometer-like function tells you cumulative stats like how far you’ve come and how high you’ve climbed.

GPS and your computer: GPS units come with a powerful software program that lets you manage maps, plan routes, analyze trips and more. Invest the time to learn it and to practice using all of its capabilities.

5 0
3 years ago
blank lines are used to see inside the product?blank lines are used to see inside the product what are they called ​
mixer [17]

Answer:

Do you have anymore information about this?

7 0
3 years ago
Hareem and Shahad are on a road trip to Florida. They pull over to get gas, and as you may know it is sold by the gallon in the
Alona [7]

Answer:

53.3

Explanation:

4×14=56

56÷1.05=53.3

4 0
3 years ago
Other questions:
  • Why is my lawn mower not starting?
    9·1 answer
  • The difference between ideal voltage source and the ideal current source​
    7·2 answers
  • In the 1960s through 1980s, a medical filter manufacturer in Ann Arbor discharged 1,4-dioxane (an industrial solvent) directly i
    10·1 answer
  • A pressure gage connected to a tank reads 50 psi at a location where the barometric reading is 29.1 inches Hg. Determine the abs
    6·1 answer
  • What is compression ratio of an Otto cycle? How does it affect the thermal efficiency of the cycle?
    14·1 answer
  • How does java achieve portable
    13·1 answer
  • What is the function of engineering
    6·1 answer
  • Write the 5 important of profession education in a point​
    10·1 answer
  • Write a program that takes three numbers as input from the user, and prints the largest.
    12·1 answer
  • The metric ruler is typically divided into
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!