Операционные системы. Замятин А.В - 77 стр.

UptoLike

Составители: 

77
int full;
pthread_mutex_t mx;
pthead_cond_t cond;
int data;
void *writer(void *)
{
while(1)
{
int t= write_to_buffer ();
pthread_mutex_lock(&mx)
while(full) {
pthread_cond_wait(&cond, &mx);
}
data=t;
full=1;
pthread_cond_signal(&mx);
pthread_mutex_unlock(&mx);
}
return NULL;
}
void * reader(void *)
{
while (1)
{
int t;
pthread_mutex_lock(&mx);
while (!full)
{
pthread_cond_wait(&cond, &mx);
}
t=data;
full=0;
pthread_cond_signal(&mx);
pthread_mutex_unlock(&mx);
read_from _buffer();
}
return NULL;
}