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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started