Question: Problem 2 - Threads and Semaphores: designing a concurrent system The two distant cities NorthTown and South Town each have a large train station but

 Problem 2 - Threads and Semaphores: designing a concurrent system The

Problem 2 - Threads and Semaphores: designing a concurrent system The two distant cities NorthTown and South Town each have a large train station but the two cities are connected by a single-track railroad. To prevent trains from crashing, it is forbidden for two trains travelling in opposite directions to be on the track at the same time. However, it is allowed for several trains to share the track if they all travel in the same direction. We model this scenario with the program below: North-bound trains ? obtain permission to depart from South Town 2 travel from South Town to North Town 3 ? leave the track and arrive in North Town South-bound trains 1 ? obtain permission to depart from North Town 2 travel from North Town to South Town 3 ? leave the track and arrive in South Town This program is to be executed by an arbitrary number of concurrent threads. Each thread goes in one or the other direction. Your job is to implement the synchronization procedures (i.e. the four lines in italics) with semaphores and/or shared variables. Propose a java solution using just one semaphore

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!