Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

OPERATING SYSTEM [SHOW IN DETAILS IN STEP BY STEP] SEMAPHORE Following is the solution of the Producer-consumer problem using semaphores. Producers produce new items and

OPERATING SYSTEM [SHOW IN DETAILS IN STEP BY STEP]

SEMAPHORE

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Following is the solution of the Producer-consumer problem using semaphores. Producers produce new items and put those items in the buffer, where Consumers consume items from the buffer and empty the buffer. 3 semaphores have been used in this solution - mutex, countEmpty, and countFull. procedure producer() { while (true) { item = producedItem(); wait(countEmpty); wait (mutex); putIntoBuffer(item); signal (mutex); signal (count Full); } } procedure consumer() { while (true) { wait(countFull); wait (mutex); item = removeFromBuffer(); signal (mutex); signal (count Empty); consumeItem(item); } } The definition of wait and signal function of semaphores are given below. Definition of wait(): Definition of signal(): wait(semaphore *s) { S->value--; if (S->value list; block; } signal(semaphore *S) { S->value++; if (S->value list; wakeup(P); } problem O points possible (ungraded) Suppose, there are three producers P1, P2, P3, and P4 who want to produce and put items in the buffer. And, there are four consumers C1, C2, and C3 who want to consume items from the buffer. No process takes more than 5 units of time to complete unless the process goes to the waiting queue(S->list) of semaphore. At a certain point of the execution, following are the values of the semaphores: mutex=1, countEmpty=2, countFull=8 Find the output of the following sequence of commands. At time 0: P1 started At time 0: P2 started At time 10:P3 started At time 10: P4 started Value of countEmpty: Value of countFull: Processes in the waiting queue of the semaphore: [Write process names with Capital letter, For example: P7. If there are multiple process writes their names using comma, For example: P6,P7. If there is no process in the semaphore's list, write EMPTY in the box] At time 15:01 started Value of countEmpty: Value of countFull: Processes in the waiting queue of the semaphore: [Write process names with Capital letter, For example: P7. If there are multiple process writes their names using comma, For example: P6,P7. If there is no process in the semaphore's list, write EMPTY in the box] At time 20 :C2 started At time 25:C3 started Value of countEmpty: Value of countFull: Processes in the waiting queue of the semaphore: [Write process names with Capital letter, For example: P7. If there are multiple process writes their names using comma, For example: P6,P7. If there is no process in the semaphore's list, write EMPTY in the box] Submit You have used 0 of 2 attempts

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

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions