Operating System 8
Operating System 8
Operating System 8
Roll: 2100290110050
Lab: Operating System
Batch: A2
sem_t mutex,writeblock;
int data = 0,rcount = 0;
int main()
{
int i,b;
pthread_t rtid[5],wtid[5];
sem_init(&mutex,0,1);
sem_init(&writeblock,0,1);
for(i=0;i<=2;i++)
{
pthread_create(&wtid[i],NULL,writer,(void
*)i);
pthread_create(&rtid[i],NULL,reader,(void
*)i);
}
for(i=0;i<=2;i++)
{
pthread_join(wtid[i],NULL);
pthread_join(rtid[i],NULL);
}
return 0;
}
Output: