diff --git a/C_Language/TP_SYS/tp_sema/consommateur.c b/C_Language/TP_SYS/tp_sema/consommateur.c index b7a1fdf..8279d88 100644 --- a/C_Language/TP_SYS/tp_sema/consommateur.c +++ b/C_Language/TP_SYS/tp_sema/consommateur.c @@ -49,21 +49,28 @@ int main( int argc, char **argv) signal(SIGINT, quitter); signal(SIGQUIT, quitter); - initscr() ; /* initialisation (obligatoire) de curses */ - noecho() ; /* suppression de l'echo des caracteres tapes*/ - cbreak() ; /* lecture non bufferisee */ - if((shmid = shmget(shm_key, sizeof(MEMP), IPC_CREAT|IPC_EXCL|0766)) == -1) - { perror("shmget"); exit(EXIT_FAILURE);} + { + perror("shmget"); + exit(EXIT_FAILURE); + } if((memoireP = (MEMP *) shmat(shmid, 0 , 0766)) == (void *) -1) - { perror("shmat"); exit(EXIT_FAILURE); } + { + perror("shmat"); + exit(EXIT_FAILURE); + } if((mutex_data = creat_sem( sem_key_data, 1)) == -1) - { perror("creat_sem"); exit(EXIT_FAILURE); } + { + perror("creat_sem"); exit(EXIT_FAILURE); + } if((mutex_tpa = creat_sem( sem_key_tpa, 1)) == -1) - { perror("creat_sem"); exit(EXIT_FAILURE); } + { + perror("creat_sem"); + exit(EXIT_FAILURE); + } temp.tete = 0; temp.queue = 0; @@ -87,6 +94,10 @@ int main( int argc, char **argv) // Si != 0 et si nbDeProd = 0 alors on quitte int premier_lancement = 0; + initscr() ; /* initialisation (obligatoire) de curses */ + noecho() ; /* suppression de l'echo des caracteres tapes*/ + cbreak() ; /* lecture non bufferisee */ + for( i = 0; i < MAX_PROD; i++) { tWindow[i] = creation_fenetre(LINES / MAX_PROD, i*(LINES/MAX_PROD), "En attente"); diff --git a/C_Language/TP_SYS/tp_sema/producteur.c b/C_Language/TP_SYS/tp_sema/producteur.c index 8729f1b..3f58ee0 100644 --- a/C_Language/TP_SYS/tp_sema/producteur.c +++ b/C_Language/TP_SYS/tp_sema/producteur.c @@ -49,7 +49,13 @@ int main( int argc, char **argv) P(mutex_tpa); for(i = 0; i < MAX_PROD && memoireP->tpa[i] != -1 ; i++); - if(memoireP->tpa[i] != -1) { V(mutex_tpa); exit(EXIT_FAILURE); } + // Si on n'a plus de place dans le TPA (tous pris) alors on quitte + if(memoireP->tpa[i] != -1) + { + V(mutex_tpa); + printf("Plus de place dispo dans les producteurs"); + exit(EXIT_FAILURE); + } memoireP->tpa[i] = 0; V(mutex_tpa); @@ -68,7 +74,7 @@ int main( int argc, char **argv) { P(mutex_data); - if(((memoireP->queue -1) % MAX_BUF) != (memoireP->tete % MAX_BUF) ) + if(((memoireP->queue -1 + MAX_BUF) % MAX_BUF) != (memoireP->tete % MAX_BUF) ) { memoireP->f[memoireP->tete].c = c; memoireP->f[memoireP->tete].idp = i; diff --git a/C_Language/TP_SYS/tp_sema/rapport b/C_Language/TP_SYS/tp_sema/rapport index 4cfdb38..8ee4584 100644 --- a/C_Language/TP_SYS/tp_sema/rapport +++ b/C_Language/TP_SYS/tp_sema/rapport @@ -9,4 +9,6 @@ Faire marcher le programme : Le consommateur peut se terminer avec un CTRL_C. Idem pour le producteur, qui peut également quitter avec un CTRL_D. -Le consommateur est programmé pour quitter si tous les producteurs partent. +Le consommateur est programmé pour quitter si les producteurs actifs partent. + +