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

UptoLike

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

239
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;