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

affichage terminé

parent 56210a76
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@ pthread_mutex_t *mutex;
pthread_barrier_t b;
bool end = false;
int personsFinished=0;
struct habitant{
int num_thread;
......@@ -35,6 +36,7 @@ struct camionette{
int i_site;
int nbSites;
int nbornes;
int nbHabs;
};
struct site{
......@@ -59,6 +61,7 @@ int main(int argc, char **argv){
int nbHabs = atoi(argv[2]); //H 100
int nbTrajets = atoi(argv[3]); //M 10
int nbBorne = atoi(argv[4]); //N 10
nbSites += 1;
srand(0);
......@@ -72,14 +75,14 @@ int main(int argc, char **argv){
sites[j].nb_bikesParked = nbBorne-2;
sites[j].nb_P_waiting = 0;
}
sites[0].nb_bikesParked = 0; //depot avec 0 velos au depart
sites[DEPOT].nb_bikesParked = 0; //depot avec 0 velos au depart
camion->i_site = 0;
camion->n_Velo = CAMION_CAPACITE_TYP;
camion->nbornes = nbBorne;
camion->num_thread = nbHabs;
camion->nbSites = nbSites;
camion->nbHabs = nbHabs;
sem_BikeFree = malloc(sizeof(sem_t)*nbSites);
sem_BorneFree = malloc(sizeof(sem_t)*nbSites);
......@@ -139,11 +142,13 @@ int main(int argc, char **argv){
free(sem_BikeFree);
free(sem_BorneFree);
free(mutex);
printf("***************** CYCLING TERMINATED ***************\n");
int sum=0;
for(int i=0; i<nbSites; i++){
for(int i=1; i<nbSites; i++){
printf("Terminal %d contains %d bikes\n", i, sites[i].nb_bikesParked);
sum+=sites[i].nb_bikesParked;
}
printf("nb de velos en fin de programme %d\n", sum);
printf("total number of bikes in town: %d, in depot: %d, in truck: %d, total: %d\n", sum, sites[DEPOT].nb_bikesParked, camion->n_Velo, camion->n_Velo+sites[DEPOT].nb_bikesParked+sum);
free(habs);
free(camion);
......@@ -233,14 +238,13 @@ void *habitants(void *arg){
hab->i_site = j;
hab->nb_trajet += 1;
}
//printf("machin bidule finished : %d, tot_trajets = %d\n", hab->num_thread, hab->nb_trajet);
printf("person %d stops\n", hab->num_thread);
pthread_mutex_lock(&mutex[hab->i_site]);
personsFinished += 1;
pthread_mutex_unlock(&mutex[hab->i_site]);
pthread_barrier_wait(&b);
//printf("machin bidule a passé la barriere !!!! : %d, tot_trajets = %d\n", hab->num_thread, hab->nb_trajet);
pthread_mutex_lock(&mutex[hab->i_site]);
end = true;
pthread_mutex_unlock(&mutex[hab->i_site]);
return NULL;
}
......@@ -248,7 +252,7 @@ void *Camion(void *arg){
struct camionette *camion = (struct camionette*)arg;
int tmp_nbBikes;
while(!end){
while(personsFinished < camion->nbHabs){
//1 : for each sites from 1 to S (0 is the depot)
for(int i=1; i<camion->nbSites; i++){
//spreads the bikes evenly
......@@ -314,8 +318,9 @@ void *Camion(void *arg){
}
//3: pause betweem 100us up to 199us
usleep(rand_Dc());
printf("TRUCK new loop, person's threads finished: %d\n", personsFinished);
}
printf("end camion\n");
printf("TRUCK end loop\n");
return NULL;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment