Question
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
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.
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:
- Lets 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.
- 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
- 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.
Producer Process Consumer Process //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: 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; 1: 2: 3: 4: 5: 6: 7: 8: 9: while (1) { while (in == out) ;* do nothing */ nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE: /* consume the item in nextConsumed */ }Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started