stable
This commit is contained in:
		
							parent
							
								
									6ad5d67c7d
								
							
						
					
					
						commit
						f79da2ce71
					
				
					 1 changed files with 15 additions and 5 deletions
				
			
		| 
						 | 
					@ -72,7 +72,6 @@ int main( int argc, char **argv)
 | 
				
			||||||
		*memoireP = temp;
 | 
							*memoireP = temp;
 | 
				
			||||||
	V(mutex_data);
 | 
						V(mutex_data);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
	sleep(5);
 | 
					 | 
				
			||||||
	// nbDeProd => est-ce qu'il y a des producteur (si 0 on quitte)
 | 
						// nbDeProd => est-ce qu'il y a des producteur (si 0 on quitte)
 | 
				
			||||||
	int nbDeProd;
 | 
						int nbDeProd;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -80,6 +79,11 @@ int main( int argc, char **argv)
 | 
				
			||||||
	int numTete = 0;
 | 
						int numTete = 0;
 | 
				
			||||||
	int vartemp;
 | 
						int vartemp;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Variable temporaire qui indique le premier lancement du consommateur.c
 | 
				
			||||||
 | 
						// Si = 0 alors aucun producteur ne s'est connecté, on ne quitte pas le programme
 | 
				
			||||||
 | 
						// Si != 0 et si nbDeProd = 0 alors on quitte
 | 
				
			||||||
 | 
						int premier_lancement = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Création des fenêtres MARCHE
 | 
						// Création des fenêtres MARCHE
 | 
				
			||||||
    f_haut = creation_fenetre(LINES/NB_FENETRES,0,"F_HAUT") ;
 | 
					    f_haut = creation_fenetre(LINES/NB_FENETRES,0,"F_HAUT") ;
 | 
				
			||||||
    f_milieu1 = creation_fenetre(LINES/NB_FENETRES,LINES - 3 * (LINES/NB_FENETRES),"F_MILIEU1") ;
 | 
					    f_milieu1 = creation_fenetre(LINES/NB_FENETRES,LINES - 3 * (LINES/NB_FENETRES),"F_MILIEU1") ;
 | 
				
			||||||
| 
						 | 
					@ -91,10 +95,17 @@ int main( int argc, char **argv)
 | 
				
			||||||
		// On (re)met nbDeProd à 0 
 | 
							// On (re)met nbDeProd à 0 
 | 
				
			||||||
		nbDeProd = 0;
 | 
							nbDeProd = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// On vérifie qu'il y ait toujours des producteurs MARCHE
 | 
							// On vérifie qu'il y ait toujours des producteurs
 | 
				
			||||||
 | 
							P(mutex_tpa);
 | 
				
			||||||
		for(i = 0 ; i < MAX_PROD && nbDeProd == 0 ; i++ )
 | 
							for(i = 0 ; i < MAX_PROD && nbDeProd == 0 ; i++ )
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
			if(memoireP->tpa[i] != -1)
 | 
								if(memoireP->tpa[i] != -1)
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
				nbDeProd++;
 | 
									nbDeProd++;
 | 
				
			||||||
 | 
									premier_lancement++;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							V(mutex_tpa);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		P(mutex_data);
 | 
							P(mutex_data);
 | 
				
			||||||
			vartemp = (int) memoireP->tete;
 | 
								vartemp = (int) memoireP->tete;
 | 
				
			||||||
| 
						 | 
					@ -105,7 +116,6 @@ int main( int argc, char **argv)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			numTete = vartemp;
 | 
								numTete = vartemp;
 | 
				
			||||||
			c = msgtemp.c;
 | 
								c = msgtemp.c;
 | 
				
			||||||
			//w =  tprod[msgtemp.idp].w;
 | 
					 | 
				
			||||||
			w = f_haut;
 | 
								w = f_haut;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			waddch(w,c) ;
 | 
								waddch(w,c) ;
 | 
				
			||||||
| 
						 | 
					@ -119,7 +129,7 @@ int main( int argc, char **argv)
 | 
				
			||||||
		V(mutex_data);
 | 
							V(mutex_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// S'il n'y a plus de producteurs, on quitte
 | 
							// S'il n'y a plus de producteurs, on quitte
 | 
				
			||||||
		if(nbDeProd == 0)
 | 
							if(nbDeProd == 0 && premier_lancement != 0)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if(shmctl(shmid, IPC_RMID, 0) < 0)
 | 
								if(shmctl(shmid, IPC_RMID, 0) < 0)
 | 
				
			||||||
			{ perror("shmctl"); exit(EXIT_FAILURE); }
 | 
								{ perror("shmctl"); exit(EXIT_FAILURE); }
 | 
				
			||||||
| 
						 | 
					@ -130,7 +140,7 @@ int main( int argc, char **argv)
 | 
				
			||||||
			endwin() ;
 | 
								endwin() ;
 | 
				
			||||||
			exit(EXIT_SUCCESS);
 | 
								exit(EXIT_SUCCESS);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		usleep(10); // Ralentissement volontaire du programme
 | 
							usleep(5); // Ralentissement volontaire du programme
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
	exit(EXIT_FAILURE);
 | 
						exit(EXIT_FAILURE);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue