Code Example Include Include Include Include Include Include Semaphore Add Addtional Threa Q37087536

Programming Assignment 2 You will create a multithreaded application using pthread library to spawn multiple reader threads a

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

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.