28.11.2014 Views

System call - Processi, thread

System call - Processi, thread

System call - Processi, thread

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Operazioni sul buffer<br />

/*ESTRAZIONE: */<br />

int estrai (prodcons *b)<br />

{ int data;<br />

p<strong>thread</strong>_mutex_lock (&b->lock);<br />

while (b->cont==0) /* il buffer e` vuoto? */<br />

p<strong>thread</strong>_cond_wait (&b->notempty, &b->lock);<br />

/* Leggi l'elemento e aggiorna lo stato del buffer*/<br />

data = b->buffer[b->readpos];<br />

b->cont--;<br />

b->readpos++;<br />

if (b->readpos >= BUFFER_SIZE)<br />

b->readpos = 0;<br />

/* Risveglia eventuali <strong>thread</strong>s (produttori)*/<br />

p<strong>thread</strong>_cond_signal (&b->notfull);<br />

p<strong>thread</strong>_mutex_unlock (&b->lock);<br />

return data;<br />

}<br />

M-fosset - Sistemi Operativi 2004-2005

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!