Skip to content
Snippets Groups Projects
Commit 27b2f7d1 authored by remi.greub's avatar remi.greub
Browse files

modifs city.h et main.c

parent a0777a03
No related branches found
No related tags found
No related merge requests found
...@@ -11,25 +11,26 @@ ...@@ -11,25 +11,26 @@
#include <semaphore.h> #include <semaphore.h>
#define CITY_CAPACITY_MIN 2 #define CITY_CAPACITY_MIN 2 //min nb of bikes
#define DEPOT 0 #define DEPOT 0 //depot's index
#define USLEEP 0
#define USLEEP 1 //activate usleep() = 1 or no = 0
struct terminal{ struct terminal{
int nb_bikesParked; int nb_bikesParked; //number of bikes parked in terminal
int nb_P_waiting; int nb_P_waiting; //number of persons waiting in terminal
sem_t *sem_FreeSlot; sem_t *sem_FreeSlot; //semaphore of the free parking slots -> one each terminal
sem_t *sem_BikeFree; sem_t *sem_BikeFree; //semaphore of the free bike -> one each terminal
pthread_mutex_t *mutex; pthread_mutex_t *mutex; //mutex -> one for each terminal
}; };
struct city{ struct city{
int npersons; int npersons; //nb of persons in the city
int nSlots; int nSlots; //nb of slots for each terminal
int nTerminal; int nTerminal; //nb of terminals in the city
int personsFinished; int personsFinished; //nb of persons that finished it's iterations
pthread_barrier_t b; pthread_barrier_t b; //barrier to wait for every person before ending the programm
struct terminal *terminals; struct terminal *terminals; //all the terminals in the city
}; };
void init_city(struct city* city, int nbTerminals, int npersons, int nbSlots); void init_city(struct city* city, int nbTerminals, int npersons, int nbSlots);
......
...@@ -29,10 +29,8 @@ int main(int argc, char **argv){ ...@@ -29,10 +29,8 @@ int main(int argc, char **argv){
struct person *persons = malloc(sizeof(struct person)*nbpersons); struct person *persons = malloc(sizeof(struct person)*nbpersons);
struct Truck truck; struct Truck truck;
init_city(&city, nbterminals, nbpersons, nbslots); init_city(&city, nbterminals, nbpersons, nbslots);
printf("COUOCU COUCOU COUCOU %d\n",city.npersons);
init_civilians(persons, &city, nbTravels); init_civilians(persons, &city, nbTravels);
init_truck(&truck, &city); init_truck(&truck, &city);
printf("COUOCU COUCOU COUCOU \n");
if(pthread_create(threadTruck, NULL, trucks, (void*)&truck)!=0){ if(pthread_create(threadTruck, NULL, trucks, (void*)&truck)!=0){
perror("thread creation error"); perror("thread creation error");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment