example2.h 368 B

12345678910111213141516171819202122
  1. #include <pthread.h>
  2. #include <stdlib.h>
  3. #include <semaphore.h>
  4. #include <stdio.h>
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #define BUFFER_SIZE 10
  8. typedef struct buffer
  9. {
  10. sem_t empty;
  11. sem_t full;
  12. pthread_mutex_t mutex;
  13. int pos;
  14. int data[BUFFER_SIZE];
  15. } buffer;
  16. void * produce(void *buf);
  17. void * consume(void *buf);
  18. void init_buffer(buffer *buf);