UFMG - Pós-graduação em Ciência da Computação - Programação Paralela

A seguir: Exclusão Mútua Acima: Regiões Críticas Anterior: O Par Produtor-Consumidor: Processos


O Par Produtor-Consumidor: Buffer


char B[10];int p=0, c=0, n=0;
 
int Put(char x) $\{$ 
		 boolean ok = false;
		 if(n < 10) $\{$		 		 B[p] = x; p = (p+1) % 10; n++; ok =  true;
		 $\}$;		 return ok;
$\}$ 
int Get(char *x) $\{$		 boolean ok = false;
		 if (n > 0) $\{$		 		 *x = B[c]; c = (c+1) % 10; n-; ok = true;
		 $\}$;		 return ok;
$\}$



Osvaldo Carvalho