Question: I ILITUM . 2 Question 5 (1 points): Consider the following code that uses semaphores: sem_t a, b; int x = 0; void foo() {

 I ILITUM . 2 Question 5 (1 points): Consider the followingcode that uses semaphores: sem_t a, b; int x = 0; void

I ILITUM . 2 Question 5 (1 points): Consider the following code that uses semaphores: sem_t a, b; int x = 0; void foo() { sem_wait(&a); write(STDOUT_FILENO, "A"); x = x + 1; sem_post(&a); write(STDOUT_FILENO, "B"); sem_wait(&b); write(STDOUT_FILENO, "C"); void bar() { sem_wait(&a); while (x > 1) { write(STDOUT_FILENO, "D"); sem_post(&b); x = x - 1; write(STDOUT_FILENO, "E"); sem_post(&a); Suppose the a semaphore is initialized to 1 and the b are semaphores is initialized to o by code not shown, and no code other than the initialization code and the code above uses these semaphores or changes the value x. Which of the following are possible outputs from multiple threads calling foo() and bar() multiple times? Select all that apply A. ODABCE B. ABDABECDEC C. ABABDEDECC D. ABDEC E. O AABBDCEDCE I ILITUM . 2 Question 5 (1 points): Consider the following code that uses semaphores: sem_t a, b; int x = 0; void foo() { sem_wait(&a); write(STDOUT_FILENO, "A"); x = x + 1; sem_post(&a); write(STDOUT_FILENO, "B"); sem_wait(&b); write(STDOUT_FILENO, "C"); void bar() { sem_wait(&a); while (x > 1) { write(STDOUT_FILENO, "D"); sem_post(&b); x = x - 1; write(STDOUT_FILENO, "E"); sem_post(&a); Suppose the a semaphore is initialized to 1 and the b are semaphores is initialized to o by code not shown, and no code other than the initialization code and the code above uses these semaphores or changes the value x. Which of the following are possible outputs from multiple threads calling foo() and bar() multiple times? Select all that apply A. ODABCE B. ABDABECDEC C. ABABDEDECC D. ABDEC E. O AABBDCEDCE

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!