Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Topic: Inter-process Communication - Shared Memory (15) In context of cooperating processes, conventional producer consumer problem is a common example. The producer process produces an

image text in transcribed

Topic: Inter-process Communication - Shared Memory (15) In context of cooperating processes, conventional producer consumer problem is a common example. The producer process produces an item that is to be consumed by the consumer process. The implementation of this problem is achieved through the use of a bounded buffer which is a region shared by both of the processes. Questions: a. Let's consider that the first process to run in this scenario is the consumer process, consider that the consumer process is permitted to run for almost 1000 machine cycles (the exact number of machine cycles consumed by the consumer process are not relevant, the purpose to mention this is that the consumer process runs for a long time). Considering the above mentioned scenario, describe what happens, the illustration should include any alteration to the values of shared variables and which statements of the consumer process executes i.e. flow of control of statements. Producer Process Consumer Process //Memory region shared by the producer and consumer process: #define BUFFERSIZE 10 typedef struct 6. Now consider that the consumer process is finally swapped out to give chance to the producer process to run, consider that the producer process is permitted to run for almost 1000 machine cycles (the exact number of machine cycles consumed by the producer process are not relevant, the purpose to mention this is that the producer process runs for a long time, adequate time to full the bounded buffer). Considering the above mentioned scenario, describe what happens, the illustration should include any alteration to the values of shared variables and which statements of the producer process executes i.e. flow of control of statements } item; item buffer[BUFFERSIZE]; int in = 0; int out = 0; item nextProduced: item nextConsumed: 1: 1: am 13 4: 5: 6: 7: while (1) /* produce an item in nextProduced */ while (in + 1) % BUFFERSIZE) == out) ; /* do nothing * buffer[in] =nextProduced: in = (in + 1) % BUFFER_SIZE; } c. Answers to Part (a) and (b) should have explained a considerable waste of computer resources i.e. "busy waiting". To answer this part, consider that we have restarted both producer and consumer processes, i.e. both are just ready to start using the shared memory variable with their vales initialized in the above given code. Explain one favored sequence of statement executions process runs till process runs till process runs till--- etc. while (1) { while (in == out) i /* do nothing * nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; /* consume the item in nextConsumed */ #Ndo 9 You may consider The given answer should clearly explain how it would be possible for the producer to produce and for the consumer to consume thousands of items without suffering from the busy waiting. Warning: The above given pseudo code is exposed to many race conditions, but the given question has nothing to do with this limitation. The provided answer should focus on the process scheduling and use of shared memory region. Both processes are sharing a single processor There can be several other processes there may be many other processes claiming for the same processor. The information about the process scheduling algorithm is not provided. The machinery for sharing the memory regions for the bounded buffer, in, and "out" has been achieved correctly through proper OS calls. Activate Windows Go to PC settings to activate Windows

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

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

3. Who would the members be?

Answered: 1 week ago