code example:
#include<stdio.h>#include<string.h>#include<pthread.h>#include<stdlib.h>#include<unistd.h>#include <semaphore.h> /* Semaphore *///add addtional threads to tid arraypthread_t tid[2];int data=0;//add additional semaphoresem_t mutex; //semphare mutex to protect data//the easiest way to keep track of number of readers in c.s.//is to have a global variable//then you need to protect this variable from being modified by//multiple readers at the same timevoid* writer(void *arg){ while(1){ sleep(2);//Don’t
OR
OR