Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <traffic.h>
- #include <pthread.h>
- #define map_width 23
- #define map_height 6
- static map_shorts map_def[] =
- {
- __,__,__,__,__,__,__,__,__,__,__,__,__,__,AU,__,__,__,__,__,__,__,__,
- __,SG,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SE,__,
- __,SG,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SE,__,
- __,SG,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SE,__,
- __,SG,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SH,SE,__,
- __,__,__,__,__,__,__,__,__,__,__,__,__,__,AU,__,__,__,__,__,__,__,__
- };
- pthread_t cars[5];
- void driving(int arg[]);
- void singalLights();
- pthread_barrier_t barriere;
- int mainloop(void* args){
- int a[3] = {21, 1, 5};
- int b[3] = {20, 2, 6};
- int c[3] = {19, 3, 7};
- int d[3] = {18, 4, 3};
- pthread_barrier_init(&barriere, NULL, 5);
- pthread_create(&cars[0], NULL, &driving, &a);
- pthread_create(&cars[1], NULL, &driving, &b);
- pthread_create(&cars[2], NULL, &driving, &c);
- pthread_create(&cars[3], NULL, &driving, &d);
- pthread_create(&cars[4], NULL, &singalLights, NULL);
- waitAndClose();
- return 0;
- }
- void driving(int arg[]){
- int id = putCar(arg[0], arg[1], W, arg[2]);
- int i;
- for(i=arg[0]; i>1; i--){
- if(i == 14)
- pthread_barrier_wait(&barriere);
- moveCar(id, W);
- }
- }
- void singalLights(){
- int id1 = putSignal(13, 1, O);
- int id2 = putSignal(13, 2, O);
- int id3 = putSignal(13, 3, O);
- int id4 = putSignal(13, 4, O);
- pthread_barrier_wait(&barriere);
- switchOn(id4);
- switchOn(id1);
- switchOn(id2);
- switchOn(id3);
- }
- int main(){
- createMap(map_def, map_width, map_height, mainloop);
- printf("Hi");
- return 0;
- }
Add Comment
Please, Sign In to add comment