Question
A single-lane bridge connects the two Vermont villages of North Tunbridge and South Tunbridge. Farmers in the two villages use this bridge to deliver their
A single-lane bridge connects the two Vermont villages of North Tunbridge and South Tunbridge. Farmers in the two villages use this bridge to deliver their produce.
the neighboring town. The bridge can become deadlocked if a northbound and a southbound farmer get on the bridge at the same time. (Vermont farmers are stubborn and are unable to back up.) Using semaphores and/or mutex locks, design an algorithm in pseudocode that prevents deadlock. Initially, do not be concerned about starvation (the situation in which northbound farmers prevent southbound farmers from using the bridge, or vice versa).
a) Write the pseudocode algorithm.
b) Modify your solution so that it is starvation-free.
c) Implement your solution using POSIX synchronization. In particular, represent northbound and southbound farmers as separate threads. Once a farmer is on the bridge, the associated thread will sleep for a random period of time, representing traveling across the bridge. Design your program so that you can. create several threads representing the northbound and southbound farmers. ex§. (3 southbound, 4 northbound) or (2 southbound, 5 northbound) or (4 southbound, 1 northbound), etc. Note: the number of southbound and
northbound farmers will be provided on the command line.
Step by Step Solution
3.42 Rating (158 Votes )
There are 3 Steps involved in it
Step: 1
Answer a semaphore oktocross 1 void enterbridge Poktocross void exitbridge Vok tocross b monitor bridge int numwaitingnorth 0 int numwaitingsouth 0 int onbridge 0 condition oktocross int prev 0 void e...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
Document Format ( 2 attachments)
6368aa3dd88a0_239809.pdf
180 KBs PDF File
6368aa3dd88a0_239809.docx
120 KBs Word File
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started