example2.h 367 B

123456789101112131415161718192021
  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. sem_t empty;
  10. sem_t full;
  11. pthread_mutex_t mutex;
  12. int pos;
  13. int data[BUFFER_SIZE];
  14. } buffer;
  15. void *produce(void *buf);
  16. void *consume(void *buf);
  17. void init_buffer(buffer * buf);