123456789101112131415161718192021 |
- #include <pthread.h>
- #include <stdlib.h>
- #include <semaphore.h>
- #include <stdio.h>
- #include <stdio.h>
- #include <unistd.h>
- #define BUFFER_SIZE 10
- typedef struct buffer {
- sem_t empty;
- sem_t full;
- pthread_mutex_t mutex;
- int pos;
- int data[BUFFER_SIZE];
- } buffer;
- void *produce(void *buf);
- void *consume(void *buf);
- void init_buffer(buffer * buf);
|