Secondo me bastano i semafori per quanto chiede la traccia
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <time.h>
#define MAX 10
int A[MAX];
sem_t W1, W2;
void * writer_process(void * arg){
int i = 0;
time_t start = time(0), s, t = 0;
while(t < 5 * MAX){
s = time(0) - start;
if(t != s){
t = s;
s = t % 5;
if(s == 1){
A[i] = i + 1;
i++;
}
else if(s == 2)
sem_post(&W1);
else if(s == 3)
sem_post(&W2);
}
}
}
void * reader1_process(void * arg){
for(int i = 0; i < MAX; i++){
sem_wait(&W1);
printf("Lettore 1 legge A[%d] = %d\n", i, A[i]);
}
}
void * reader2_process(void * arg){
for(int i = 0; i < MAX; i++){
sem_wait(&W2);
printf("Lettore 2 legge A[%d] = %d\n", i, A[i]);
}
}
int main(){
pthread_t wr, rd1, rd2;
sem_init(&W1,0,0);
sem_init(&W2,0,0);
pthread_create( &wr, NULL, writer_process, NULL);
pthread_create(&rd1, NULL, reader1_process, NULL);
pthread_create(&rd2, NULL, reader2_process, NULL);
pthread_join( wr, NULL);
pthread_join(rd1, NULL);
pthread_join(rd2, NULL);
return 0;
}