
















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

















Binary Semaphore Primitives
Consequences
Example of Semaphore Mechanism
Mutual Exclusion
How would you fix the code? #include <pthread.h> #include <stdio.h> int sum; /* this data is shared by the thread(s) */ void *runner(void param); / the thread / main(int argc, char argv[]) { pthread_t tidl, tid; / the thread identifier / pthread_attr_t attr; / set of thread attributes / if (argc != 2) { fprintf(stderr, ’’usage: a.out
How would you implement… 11
Rendez-vous Requirement: Thread A has to wait for Thread B and vice-versa: a1 happens before b2 and b1 happens before a2.
Mutual Exclusion Requirement: only one thread accesses the shared variable at a time. Question: what would be the problem if mutual exclusion not enforced in this case?
Implementation of Semaphores
Producer/Consumer Problem General Situation:
Is This Correct?