Question: EXERCISE # 2 An implementation of a circular FIFO queue for multiple producers and consumers are attached in the appendix ( it is the one
EXERCISE #
An implementation of a circular FIFO queue for multiple producers and consumers are attached in the appendix it is the one we designed in our lecture Regarding the implementation:
Question #: Is it necessary to have "wait mutex and "signalmutex in the producer processes? If NO explain why not. If YES, explain why we need them.
Question #: Is there any merit in using two different "mutex semaphore" one for the producers and the other for the consumers If yes, describe what is the merit? If not, why not?
Question #: Is the implementation "starvation free" for both producers and consumers? If NO explain why it is not. If YES, explain why we it is
APPENDIX:
table#define N the queue sizeshared memory int CFQ N; the circular FIFO queueshared memory int TOP ; pointer to the top of the queueshared memory int TAIL ; pointer to the tail of the queue a mutex semaphoresemaphore mutex ; a counting semaphoresemaphore empty ; counting semaphoresemophore full ;
void producer void
int new item; place holder for a new item to insert
while TRUE
I
new item produce new item ; generate a new item
wait empty:
woit mutex;
make sure the queue is NOT full
I should be the only one
insertCFQ TAIL, new item; insert the new itern to the queue
TAL; update the Top pointer
signalmutex; t am done!
signalfull; full
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
