next up previous
Next: Buffer com sincronização interna: Up: Exclusão Mútua Previous: Exclusão Mútua

Buffer com exclusão mútua

 
key mutex;

char B[10];

int p=0, c=0, n=0;

int Put(char x) tex2html_wrap_inline710

boolean ok = false;

lock(mutex)

if(n < 10) tex2html_wrap_inline710

B[p] = x; p = (p+1) % 10; n++; ok = true;

tex2html_wrap_inline714;

unlock(mutex)

return ok;

tex2html_wrap_inline714

int Get(char *x) tex2html_wrap_inline710

boolean ok = false;

lock(mutex);

if (n > 0) tex2html_wrap_inline710

*x = B[c]; c = (c+1) % 10; n-; ok = true;

tex2html_wrap_inline714;

unlock(mutex)

return ok;

tex2html_wrap_inline714



Osvaldo Sergio F. de Carvalho
Wed Mar 19 14:56:39 EST 1997