Linux-Programming/ch12/pthread_cond_example.c
void put(producons *prod, int data)
{
	
	while (prod->readpos == (prod->writepos + 1) % BUFFER_SIZE)
	{
		printf("Producer is waiting for buffer not full.\n");
		pthread_cond_wait(&prod->notfull, &prod->lock);
	}

	pthread_mutex_lock(&prod->lock);

	// write data into buffer.
	prod->buffer[prod->writepos++] = data;
	// reset wirting position if writepos reach the end of buffer.
	if (prod->writepos >= BUFFER_SIZE)
	{
		prod->writepos = 0;
	}

	pthread_cond_signal(&prod->notempty);
	pthread_mutex_unlock(&prod->lock);
}
/* Puts an integer into buffer.*/
Puts an integer into buffer.
Puts an integer into buffer .
void put(producons *prod, int data)
{
	while (prod->readpos == (prod->writepos + 1) % BUFFER_SIZE)
	{
		printf("Producer is waiting for buffer not full.\n");
		pthread_cond_wait(&prod->notfull, &prod->lock);
	}
	pthread_mutex_lock(&prod->lock);
	prod->buffer[prod->writepos++] = data;
	if (prod->writepos >= BUFFER_SIZE)
	{
		prod->writepos = 0;
	}
	pthread_cond_signal(&prod->notempty);
	pthread_mutex_unlock(&prod->lock);
}
void put ( producons * prod , int data ) { while ( prod -> readpos == ( prod -> writepos + 1 ) % BUFFER_SIZE ) { printf ( " \n " ) ; pthread_cond_wait ( & prod -> notfull , & prod -> lock ) ; } pthread_mutex_lock ( & prod -> lock ) ; prod -> buffer [ prod -> writepos ++ ] = data ; if ( prod -> writepos >= BUFFER_SIZE ) { prod -> writepos = 0 ; } pthread_cond_signal ( & prod -> notempty ) ; pthread_mutex_unlock ( & prod -> lock ) ; }
Puts an integer into buffer.
Puts an integer into buffer .
// write data into buffer.
 // reset wirting position if writepos reach the end of buffer.
