diff --git a/G17_bykes/city.h b/G17_bykes/city.h index c1c59401a9f3daab2d7a7133c7da20a0ef3976c3..317b287dc7b756807af4550d4bf2bc0b2a3c18ec 100644 --- a/G17_bykes/city.h +++ b/G17_bykes/city.h @@ -11,25 +11,26 @@ #include <semaphore.h> -#define CITY_CAPACITY_MIN 2 -#define DEPOT 0 -#define USLEEP 0 +#define CITY_CAPACITY_MIN 2 //min nb of bikes +#define DEPOT 0 //depot's index + +#define USLEEP 1 //activate usleep() = 1 or no = 0 struct terminal{ - int nb_bikesParked; - int nb_P_waiting; - sem_t *sem_FreeSlot; - sem_t *sem_BikeFree; - pthread_mutex_t *mutex; + int nb_bikesParked; //number of bikes parked in terminal + int nb_P_waiting; //number of persons waiting in terminal + sem_t *sem_FreeSlot; //semaphore of the free parking slots -> one each terminal + sem_t *sem_BikeFree; //semaphore of the free bike -> one each terminal + pthread_mutex_t *mutex; //mutex -> one for each terminal }; struct city{ - int npersons; - int nSlots; - int nTerminal; - int personsFinished; - pthread_barrier_t b; - struct terminal *terminals; + int npersons; //nb of persons in the city + int nSlots; //nb of slots for each terminal + int nTerminal; //nb of terminals in the city + int personsFinished; //nb of persons that finished it's iterations + pthread_barrier_t b; //barrier to wait for every person before ending the programm + struct terminal *terminals; //all the terminals in the city }; void init_city(struct city* city, int nbTerminals, int npersons, int nbSlots); diff --git a/G17_bykes/main.c b/G17_bykes/main.c index 74519e546edec7f4b1c0a09097566e89cd101812..cc2b3376f8924e3463458b4bc2f1eb49648e1e59 100644 --- a/G17_bykes/main.c +++ b/G17_bykes/main.c @@ -29,10 +29,8 @@ int main(int argc, char **argv){ struct person *persons = malloc(sizeof(struct person)*nbpersons); struct Truck truck; init_city(&city, nbterminals, nbpersons, nbslots); - printf("COUOCU COUCOU COUCOU %d\n",city.npersons); init_civilians(persons, &city, nbTravels); init_truck(&truck, &city); - printf("COUOCU COUCOU COUCOU \n"); if(pthread_create(threadTruck, NULL, trucks, (void*)&truck)!=0){ perror("thread creation error");