Question
A two-way north-south highway through the mountains must pass through a narrow tunnel with only one lane. A south-bound or north-bound car can pass through
A two-way north-south highway through the mountains must pass through a narrow tunnel with only one lane. A south-bound or north-bound car can pass through the tunnel only if, when it arrives, there are no on-comming cars in the tunnel. Note, due to the length of the tunnel, at most only 3 cars are allowed in the tunnel at one timeprovided that they are all heading in the same direction. In pseudo-code write the two processes north2south and south2north that allows cars to use the tunnel safely. As a starting point use the code below. Hint: This is similar to the readers-writers problem except it is symmetricnorth2south() is similar to south2north(); Remember: All Semaphores and variables must be initialised. /* Shared Data between all processes */ Semaphore tunnel_mutex; /* Shared Data between south2north processes */ Semaphore north_mutex; Semaphore going_north_max; int number_going_north; south2north() { /* Add Synchronisation code here */ DriveNorthThroughTunnel(); /* Add Synchronisation code here */ } /* Shared Data between north2south processes */ Semaphore south_mutex; Semaphore going_south_max; int number_going_south; north2south() { /* Add Synchronisation code here */ DriveSouthThroughTunnel(); /* Add Synchronisation code here */ }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started