in Operating System
501 views
0 votes
0 votes
Given two semaphore n and s

Now given 2 situation

Situation 1) The producer will be able to add an item to the buffer, but consumer can never consume it

Situation 2) Consumer succeeds in acquiring semaphore s, when buffer is empty

What will be initial value of n and s to fulfill these two condition separately?

(U can describe the situation with few words)
in Operating System
by
501 views

2 Comments

whether n and s both are binary semaphores?

if yes, what is the size of buffer?
0
0
It is a producer consumer process

think accordingly
0
0

1 Answer

1 vote
1 vote

I think n = 0 (full semaphore) and s = 1 (empty semaphore) should be the initial values to satisfy both the conditions.

Here is my solution,

Here the mutex lock will keep both the consumer and producer from accessing the buffer while the other is at work.

Ref. https://www.geeksforgeeks.org/producer-consumer-problem-using-semaphores-set-1/

Related questions