Question: sem_t emtpty; sem_t full; void *producer(void *arg) { int i; for (i = 0; i < loops; i++) { sem_wait(&empty); put(i); // puts i in
sem_t emtpty; sem_t full; void *producer(void *arg) { int i; for (i = 0; i < loops; i++) { sem_wait(&empty); put(i); // puts i in the shared buffer sem_post(&full) } } void *consumer(void *arg) { int tmp = 0; while (tmp != -1) { sem_wait(&full); tmp = get(); // gets a value from the shared buffer sem_post(&empty); printf("%d ", tmp); } } int main(int argc, char *argv[]) { // ... sem_init(&empty, 0, 10); sem_init(&full, 0, 0); // ... } a. Identify synchronization problems that the given code has. Explain the problem. (10pts) b. Modify the code to resolve the problem using semaphores. Explain how your modifcation works. (10pts) c. Modify the code to resolve the problem using condition variables. Explain how your modifcation works. (10pts)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
