You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
• Un <strong>thread</strong> puo` sospendersi su una variabile condizione, se<br />
la condizione non e` verificata:<br />
• ad esempio:<br />
p<strong>thread</strong>_cond_t C= PTHREAD_COND_INIZIALIZER;<br />
int bufferpieno=0;<br />
...<br />
if (bufferpieno) <br />
‣ La verifica della condizione e` una sezione critica!<br />
‣ Necessita` di garantire la mutua esclusione:<br />
e` necessario associare ad ogni variabile condizione un mutex :<br />
p<strong>thread</strong>_cond_t C= PTHREAD_COND_INIZIALIZER;<br />
p<strong>thread</strong>_mutex_t M=PTHREAD_MUTEX_INITIALIZER;<br />
int bufferpieno=0;<br />
...<br />
p<strong>thread</strong>_mutex_lock(&M);<br />
if (bufferpieno) <br />
p<strong>thread</strong>_mutex_unlock(&M);<br />
M-fosset - Sistemi Operativi 2004-2005<br />
Variabili condizione: wait