Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

In this exercise you must implement in Java another classic control problem. competition - the problem of monkeys crossing the river. Problem description: Suppose there

In this exercise you must implement in Java another classic control problem. competition - the problem of monkeys crossing the river.

Problem description:

Suppose there are monkeys on both banks of the river, and from time to time the monkeys decide to go to the other side looking for food. one ticket to another river bank is made through a rope bridge. More than one monkey can cross the bridge at the same time, but this is only possible if they travel in the same direction.

Implementation:

Implement a program that controls the passage of monkeys across the bridge using concurrency control mechanism with semaphores, Java language. To test the system, create 10 threads that represent the monkeys, formulate half of them on each bank of the river. Whenever a monkey starts or completes the crossing, print a message on the screen identifying the monkey. After testing the above program, now create a new version of the program by adding two gorillas, one on each side of the river. As gorillas are very heavy, they only affect cross a bridge alone. As other monkeys are afraid of gorillas, they need to Priority to make the crossing.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions