Guest User

Untitled

a guest
Jul 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. ## Traffic Problem
  2. // Spawn 4 streets
  3. // Spawn 1 dispatcher
  4. // Shared variables: right_of_way, car_queue[]
  5.  
  6. ## Dispatcher
  7. right_of_way = 1;
  8. while(1){
  9. sleep(random); // Wait random time
  10. for(i=0;i<random;i++){ // Spawn random # of cars
  11. car_queue[random]++; // Add car to random street queue
  12. }
  13. }
  14.  
  15. ## Street
  16. while(1)
  17. if(right_of_way){
  18. if(car_queue[me]){
  19. car_queue[me]--; // Remove the car
  20. sleep(2); // Do the driving
  21. }
  22. right_of_way++; // Right-of-way to next street
  23. }
  24. }
Add Comment
Please, Sign In to add comment