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 />

/* Inserimento: */<br />

void inserisci (prodcons *b, int data)<br />

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

/* controlla che il buffer non sia pieno:*/<br />

while ( b->cont==BUFFER_SIZE)<br />

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

/* scrivi data e aggiorna lo stato del buffer */<br />

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

b->cont++;<br />

b->writepos++;<br />

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

b->writepos = 0;<br />

/* risveglia eventuali <strong>thread</strong> (consumatori) sospesi */<br />

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

p<strong>thread</strong>_mutex_unlock (&b->lock);<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!