Two Way North South Highway Mountains Must Pass Narrow Tunnel One Lane South Bound North B Q30868977

A two-way north-south highway through the mountains must passthrough a narrow tunnel with only one lane. A south-bound ornorth-bound car can pass through the tunnel only if, when itarrives, there are no on-comming cars in the tunnel. Note, due tothe length of the tunnel, at most only 3 cars are allowed in thetunnel at one time—provided that they are all heading in the samedirection. In pseudo-code write the two processes north2south andsouth2north that allows cars to use the tunnel safely. As astarting point use the code below. Hint: This is similar to thereaders-writers problem except it is symmetric—north2south() issimilar to south2north(); Remember: All Semaphores and variablesmust be initialised. /* Shared Data between all processes */Semaphore tunnel_mutex; /* Shared Data between south2northprocesses */ Semaphore north_mutex; Semaphore going_north_max; intnumber_going_north; south2north() { /* Add Synchronisation codehere */ DriveNorthThroughTunnel(); /* Add Synchronisation code here*/ } /* Shared Data between north2south processes */ Semaphoresouth_mutex; Semaphore going_south_max; int number_going_south;north2south() { /* Add Synchronisation code here */DriveSouthThroughTunnel(); /* Add Synchronisation code here */}

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *