Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
194 views
in Computer by (101k points)
closed by

The producer and consumer processes share the following variables:

Int n,

Semaphore M=1

Semaphore E=n

Semaphore F=0

The consumer process must execute ______ and before removing an item from buffer.
1. signal(M), signal(F)
2. signal(M), wait(F)
3. Signal(F), wait(M)
4. wait(F), wait(M)

1 Answer

0 votes
by (108k points)
selected by
 
Best answer
Correct Answer - Option 4 : wait(F), wait(M)

Concept:

In producer- consumer problem, producer can only produce the items when there is space in the buffer, means it has to wait for the consumer to consume the items. Similarly, consumer can consume the item only when producer produces it.

Explanation:

Given, M = 1, E = n and F =0

Here, semaphore M is for mutual exclusion, semaphore E is for empty space in buffer , semaphore F is used to define the space filled by the producer.

code for producer side:

while (true)

{

Produce()

Wait(E)

Wait(M)

Append()

Signal(M)

Signal(F)

}

Code for consumer side:

while(true){

Wait(F)

Wait(M)

Consume()

Signal(M)

Signal(E)

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...