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 @@
#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);
......
......@@ -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");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment