Procon
Procon
h>
#include <semaphore.h>
#include <pthread.h>
#include <stdlib.h>
#define Maxitems 5
#define Buffersize 5
sem_t empty;
sem_t full;
int in =0;
int out =0;
int buffer[Buffersize];
pthread_mutex_t mutex;
for(int i=0;i<5;i++)
{
pthread_create(&pro[i],NULL,(void*)producer,(void*)&a[i]);
pthread_create(&con[i],NULL,(void*)consumer,(void*)&a[i]);
}
for(int i=0;i<5;i++)
{
pthread_join(pro[i],NULL);
pthread_join(con[i],NULL);
}
pthread_mutex_destroy(&mutex);
sem_destroy(&empty);
sem_destroy(&full);
return 0;
}
in= (in+1)%Buffersize;
pthread_mutex_unlock(&mutex);
sem_post(&full);
}