1 Answers
Option 3 : P: full, Q: empty, R: empty, S: full
The correct answer is option 3.
Concept:
Given data,
Empty = 0
Full = N
Mutex = 1
Because the value of the empty semaphore is 0, you cannot wait for the empty semaphore on the first try.
Note:
The number of filled slots is represented by an empty semaphore, therefore the producer process must deal with both empty and mutex semaphores. The number of empty slots in a full semaphore is the same as the number of empty slots in a mutex semaphore, so consumer processes must deal with both full and mutex semaphores.
Option 1:
It results in starvation. It is starvation is the problem that occurs when high-priority processes keep executing and low priority processes get blocked for an indefinite time. Here Producer and consumer process is not allowed.
Option 2:
results in starvation. It producer at P condition blocks the process that there are no items to give and R conditions blocks that there is no item to consume because it is already full it means something blocking high-priority processes keep executing and low priority processes get blocked for an indefinite time.
Option 4:
Because the number of filled slots is originally 0 (as indicated by an empty semaphore), the consumer process is unable to consume. As a result, its implementation is flawed.
Option 3: P: full, Q: empty, R: empty, S: full is ensure deadlock-free and starvation-free implementation.
P: full, Q: empty, R: empty, S: full
Empty = 0
Full = N
Mutex = 1
|
Producer: |
Consumer: |
|
do { wait (full); wait (mutex); //Add item signal (mutex); signal (empty); } while (1); |
do { wait (empty); wait (mutex); //Consume item signal (mutex); signal (full); } while (1); |
Hence the correct answer is P: full, Q: empty, R: empty, S: full.