First of all, This is for a school project, so I don't expect actual code. I'm not too concerned with that. However, I'm having trouble identifying which scenario this is. The project is as follows:
Create three functions: pedestrian(), carWest(), CarEast().Your program should read the input file, and launch a thread per each traffic participant the appropriate time. Each thread should execute corresponding function. Each function should contain three sections: zone entrance, zone crossing, zone exit. Use mutexes and condition variables to ensure that the traffic crosses the construction zone according to the ODOT rules. After the entrance and exit the thread should announce (print) its action. Use sleep_for()function to implement crossing the zone. The amount of time that each participant remains in the zone corresponds to his speed.
ODOT RULES:
neither car nor pedestrians should wait if the intersection is empty; cars cannot go in the opposite directions simultaneously on the one-lane section; a pedestrian cannot cross the street while there is a car in the one-lane section, but multiple pedestrians can cross the street at the same time; a car may enter the one lane section if there is a car there going in the same direction, however, a car is not allowed to pass another car; a car does not wait for more than two cars going in the opposite direction; a pedestrian has to yield to cars BUT a pedestrian should not wait for more than two cars (in either direction).
SAMPLE COMMAND:
0 E1 10 - corresponds to: int arrival_time >> string eastCar#1 >> int speed
So, because of the wording, I'm leaning towards a single producer-many consumer solution: http://ift.tt/1OCS2b6
since the project states the main thread should launch the control thread at the appropriate time.
Does this sound correct? I can also see it being a dining-philosopher problem, here: http://ift.tt/1nL2L2K
or even as the reader-writer problem here: http://ift.tt/1VrKxbk
Thanks for setting me straight
-cos-
Aucun commentaire:
Enregistrer un commentaire