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

 Question No 3: Topic: Inter-process Communication - Shared Memory (15) In

context of cooperating processes, conventional producer consumer problem is a common example.

Question No 3: 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. Producer Process Consumer Process I/Memory region shared by the producer and consumer process: #define BUFFERSIZE 10 typedef struct { } item; item buffer[BUFFERSIZE]; int in = 0; int out = 0; item nextProduced: item nextConsumed: 1: 3: 4: 1: 2: 3: 4: 5: 6: 7: 8: 9: while (1) { /* produce an item in nextProduced */ while (in +1)% BUFFERSIZE) out) * do nothing */ buffer[in] = nextProduced; in = (in + 1) % BUFFER_SIZE; } while (1) while (in == out) _* do nothing */ nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; /* consume the item in nextConsumed */ } 7: 8: 9: . . . You may consider 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. Questions: a. Let's consider that the first process to run in this scenario is 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. b. 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 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. 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 pseudocode 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!