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

code fonctionnel2

parent 6ca09b7d
No related branches found
No related tags found
No related merge requests found
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
#define CAMION_CAPACITE_TYP 2 #define CAMION_CAPACITE_TYP 2
#define SITE_CAPACITE_MIN 2 #define SITE_CAPACITE_MIN 2
//#define NUM_THREAD 5
#define DEPOT 0 #define DEPOT 0
sem_t *sem_BorneFree; sem_t *sem_BorneFree;
...@@ -89,8 +87,8 @@ int main(int argc, char **argv){ ...@@ -89,8 +87,8 @@ int main(int argc, char **argv){
mutex = malloc(sizeof(pthread_mutex_t)*nbSites); mutex = malloc(sizeof(pthread_mutex_t)*nbSites);
for(int x =0; x<nbSites; x++){ for(int x =0; x<nbSites; x++){
sem_init(&sem_BikeFree[x], 0, 8); sem_init(&sem_BikeFree[x], 0, nbBorne-2);//8);
sem_init(&sem_BorneFree[x], 0, 2); sem_init(&sem_BorneFree[x], 0, nbBorne-(nbBorne-2));//2);
pthread_mutex_init(&mutex[x], NULL); //mutex du camion pthread_mutex_init(&mutex[x], NULL); //mutex du camion
} }
...@@ -164,14 +162,14 @@ void *habitants(void *arg){ ...@@ -164,14 +162,14 @@ void *habitants(void *arg){
while(hab->nb_trajet < hab->max_trajets){ while(hab->nb_trajet < hab->max_trajets){
//waits for a bike in site i //waits for a bike in site i
//if(hab->i_site==4){ //if(hab->i_site==4){
sem_getvalue(&sem_BorneFree[hab->i_site],&val);
pthread_mutex_lock(&mutex[hab->i_site]); pthread_mutex_lock(&mutex[hab->i_site]);
printf("(GET) person %d starts from terminal %d (%d bykes, %d persons waiting, semVal : %d)\n", hab->num_thread, hab->i_site, sites[hab->i_site].nb_bikesParked, sites[hab->i_site].nb_P_waiting, val);//sites[hab->i_site].nb_P_waiting); printf("(GET) person %d starts from terminal %d (%d bykes, %d persons waiting, semBorneFree_val : %d)\n", hab->num_thread, hab->i_site, sites[hab->i_site].nb_bikesParked, sites[hab->i_site].nb_P_waiting, val);//sites[hab->i_site].nb_P_waiting);
pthread_mutex_unlock(&mutex[hab->i_site]); pthread_mutex_unlock(&mutex[hab->i_site]);
//} //}
sem_getvalue(&sem_BorneFree[hab->i_site],&val);
if(sites[hab->i_site].nb_bikesParked<=0){// && hab->i_site == 4){ if(sites[hab->i_site].nb_bikesParked<=0){// && hab->i_site == 4){
printf("person %d is STUCK at terminal %d: rack empty with : %d bikes\n", hab->num_thread, hab->i_site, sites[hab->i_site].nb_bikesParked); printf("person %d is STUCK at terminal %d: rack empty : %d bikes\n", hab->num_thread, hab->i_site, sites[hab->i_site].nb_bikesParked);
} }
pthread_mutex_lock(&mutex[hab->i_site]); pthread_mutex_lock(&mutex[hab->i_site]);
...@@ -202,12 +200,13 @@ void *habitants(void *arg){ ...@@ -202,12 +200,13 @@ void *habitants(void *arg){
//waits for a parkinglot to be freed and deposit his bycycle //waits for a parkinglot to be freed and deposit his bycycle
//if(j==4){ //if(j==4){
sem_getvalue(&sem_BikeFree[j],&val);
pthread_mutex_lock(&mutex[j]); pthread_mutex_lock(&mutex[j]);
printf("(PUT) person %d arrives at terminal %d (%d bykes, %d persons waiting, semVal : %d)\n", hab->num_thread, j, sites[j].nb_bikesParked, sites[j].nb_P_waiting, val);//sites[j].nb_P_waiting); printf("(PUT) person %d arrives at terminal %d (%d bykes, %d persons waiting, semBikeFree_val : %d)\n", hab->num_thread, j, sites[j].nb_bikesParked, sites[j].nb_P_waiting, val);//sites[j].nb_P_waiting);
pthread_mutex_unlock(&mutex[j]); pthread_mutex_unlock(&mutex[j]);
//} //}
sem_getvalue(&sem_BikeFree[j],&val);
if(sites[j].nb_bikesParked>=hab->nbornes){//} && j == 4){ if(sites[j].nb_bikesParked>=hab->nbornes){//} && j == 4){
printf("person %d is STUCK at terminal %d: rack full : %d bikes\n", hab->num_thread, j, sites[j].nb_bikesParked); printf("person %d is STUCK at terminal %d: rack full : %d bikes\n", hab->num_thread, j, sites[j].nb_bikesParked);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment