Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

6. You are given codes for the producer and the consumer. Codes use two hypothetical system calls: sleep and wakeup(x) - sleep The issuing process

image text in transcribed
6. You are given codes for the producer and the consumer. Codes use two hypothetical system calls: sleep and wakeup(x) - sleep The issuing process X is blocked and it will stay blocked until waken up by some process that issues wakeup (X) system call. wakeup (X) This system call does not effect in any way the issuing process. If the process X has been blocked because it previously issued sleep), the process X is unblocked and put in a ready state, otherwise this system call does not have any effect #de fine N 100 int count-0 typedef struct l item iten buffer [N): Producer code: Consumer code: (item Produced: while (true item Consumed while (true if (count0) sleep /*produce an item in Produced if (count) sleep /"take an item from buffer an put into / put item from Produced Consumed count count-1 into buffer count count1 Lf (count1)wakeup (Consumer) if (countN-1) wakeup (Producer) /consume the item from Consumed a. The ecodes have an unresolved critical section problem related with the following two statements count-count +1 in producer code count-count 1 7 in consume r code We discussed that problem in the class and it is not of concern for this problem, e assume that the variable count is updated in those two statements in such way that there is no critical section problem. b. It is also assumed that access to the buffer is orderly, so no problen there. But, there is still a problen with the given codes. It is possible that both processes may execute slee system call, thus without any of them being able to execute a walkup system call. Provide one such scenario illustrating that sonething like that can happen Your scenario should be along the following lines: one process runs first and at certain point it is interrupted, and then the second process runs and after some tine is interrupted and so on, until both processes issue sleep system call. At the beginning,you should assume that Producer started first and produces some number N) of items. Note: You are not asked to fix this code

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

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions