January 13, 2016 · Public
can you help me to write this code?
"44.Single-Lane Bridge - DeadLock Prevention
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 to the neighboring town. The bridge can become deadlocked if a northbound and a southbound farmer get on the bridge at the same time. (Vermount farmers are stubborn and are unavle to back up).
Implement an algorthim that prevents deadlock 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 ."