Question
There is an intersection with cars (threads) turning right, left and straight. How to implement a concurrent thread program that only uses mutex locks. I
There is an intersection with cars (threads) turning right, left and straight. How to implement a concurrent thread program that only uses mutex locks.
I can create any number of locks.
I have the functions with arguments = gostraight(car direction, car#), goright(car direction, car#), goleft(car direction, car#).
I need to avoid deadlocks!!!.
I also have an approachintersection function with (int car number) argument. This function randomly selects a turn direction and type of turn.Every time a thread/car is created this function is called to randomly create direction and select turn type.
I need a help thinking of how to implement this without causing any race conditions or deadlocks. Pseudo code would be great, or just an explanation of how the locks should be set.
Thanks.
Modeling the intersection NE SEStep 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