程序代写 CMPUT 379, U. of Alberta, course instructor (E. Elmallah). All rights reser

Copyright Notice: Copyright by CMPUT 379, U. of Alberta, course instructor (E. Elmallah). All rights reserved. Do not post any part on a publicly-available Web site.
Question 4 (v4) [6 points]
In the following code, main() initializes three semaphores: semA= 1, semB= 0, and semC= 1. Threads R1, R2, and R3 are then started. Describe ALL possible outputs of the program. Note that each thread is loop-free. Make no assumption about the relative speed of the threads, or their relative starting instants.
sem_t semA, semB, semC;

Copyright By PowCoder代写 加微信 powcoder

void *R1 () { sem_wait(&semA); printf (“R1 \n”); sem_post(&semA); }
void *R2 () { sem_wait(&semB); printf (“R2 \n”); sem_post(&semA); }
void *R3 () { sem_wait(&semC); sem_wait(&semA);
printf (“R3 \n”);
sem_post(&semB); sem_post(&semC);
int main () {
sem_init(&semA, NULL, 1); /* semA= 1 */
sem_init(&semB, NULL, 0); /* semB= 0 */
sem_init(&semC, NULL, 1); /* semC= 1 */
/* create threads R1, R2, and R3 */
University of Alberta examination University of Alberta examination
University of Alberta examination
University of Alberta examination University of Alberta examination

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com