Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Traffic Problem
- // Spawn 4 streets
- // Spawn 1 dispatcher
- // Shared variables: right_of_way, car_queue[]
- ## Dispatcher
- right_of_way = 1;
- while(1){
- sleep(random); // Wait random time
- for(i=0;i<random;i++){ // Spawn random # of cars
- car_queue[random]++; // Add car to random street queue
- }
- }
- ## Street
- while(1)
- if(right_of_way){
- if(car_queue[me]){
- car_queue[me]--; // Remove the car
- sleep(2); // Do the driving
- }
- right_of_way++; // Right-of-way to next street
- }
- }
Add Comment
Please, Sign In to add comment