Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago