Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Provided the solution of producer/consumer problem as below: sem_t emtpty; sem_t full; void *producer(void *arg) { int i; for (i = 0; i < loops;

Provided the solution of producer/consumer problem as below:

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago