Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Two villages (Eastvillage and Westvillage) only have a single-lane road for the connection. People from these two villages only can use this road for exchange

Two villages (Eastvillage and Westvillage) only have a single-lane road for the connection. People from these two villages only can use this road for exchange or share their produce. The road can be deadlocked if a people from either East or West on the road simultaneously. To solve this problem to avoid deadlock, please design an algorithm that uses semaphores and/or mutex locks. There have no concerns for the starvation cases.

Implement your solution using synchronization tools. In particular, represent the people at Eastvillage and Westvillage as separate threads (east_village.java and west_village.java). Once a people is on the road, the associated thread will sleep for a random period of time, representing traveling across the road. You should design a new action for each people when they get into the road, such as eat a donut, to wait for some time. Design your program so that you can create several threads representing the two villages' people without deadlock in the road.

You can flexibly design the algorithm, the test should have no deadlock in the multiple execution cases.

Step by Step Solution

3.36 Rating (152 Votes )

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Management Accounting Information for Decision-Making and Strategy Execution

Authors: Anthony A. Atkinson, Robert S. Kaplan, Ella Mae Matsumura, S. Mark Young

6th Edition

137024975, 978-0137024971

More Books

Students also viewed these Computer Network questions

Question

Should firms behave ethically?

Answered: 1 week ago

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago

Question

What three critical elements does the BET metric bring together?

Answered: 1 week ago