#include #include #define BUFSIZE 8 static int buffer[BUFSIZE]; static int bufin = 0; static int bufout = 0; static pthread_mutex_t buffer_lock = PTHREAD_MUTEX_INITIALIZER; int get_buffersize(){ return BUFSIZE; } void get_item(int *itemp){ pthread_mutex_lock(&buffer_lock); *itemp = buffer[bufout]; bufout = (bufout + 1) % BUFSIZE; pthread_mutex_unlock(&buffer_lock); return; } void put_item(int item){ pthread_mutex_lock(&buffer_lock); buffer[bufin] = item; bufin = (bufin + 1) % BUFSIZE; pthread_mutex_unlock(&buffer_lock); return; }