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
922 views
in Computer by (106k points)
closed by

The following program consists of 3 concurrent processes and 3 binary semaphores. The semaphores are initialized as S0=1, S1=0, S2=0.

Process P0

Process P1

Process P2

While (true) {

Wait (S0);

Print ‘0’

Release (S1);

Release (S2);

}

Wait (S1);

Release (S0);

Wait (S2);

Release (S0);

 

How many times will process P0 print ‘0’? 


1. At least twice
2. Exactly twice
3. Exactly thrice
4. Exactly once

1 Answer

0 votes
by (106k points)
selected by
 
Best answer
Correct Answer - Option 1 : At least twice

The correct answer is option 1

Concept:

Binary semaphore which can take only two values 0 and 1 and ensure mutual exclusion.

A process is entered into the critical section only when the value of semaphore(s) = 1

Otherwise, it will wait until semaphore(s) >0

Explanation:

The semaphores are initialized as S0=1, S1=0, S2=0.

Because S0 =1 then P0 enter into the critical section and other processes will wait until either S1=1 or S2 =1

The minimum number of times 0 printed:

  • S0 =1 then P0 enter into the critical section
  • print '0'
  • then release S1 and S2 means S1 =1 and s2 =1
  • now either P1 or P2 can enter into the critical section
  • if P1 enter into the critical section
  • release S0
  • then P2 enter into the critical section
  • release S0
  • P1 enter into the critical section
  • print '0'

The minimum number of time 0 printed is twice when executing in this order (p0 -> p1 -> p2 -> p0)

The Maximum number of times 0 printed:

  • S0 =1 then P0 enter into the critical section
  • print '0'
  • Then release S1 and S2 means S1 =1 and s2 =1
  • Now either P1 or P2 can enter into the critical section
  • If P1 enter into the critical section
  • Release S0 means S0 =1
  • S0 =1 then P0 enter into the critical section
  • print '0'
  • Then P2 enter into the critical section
  • Release S0 means S0 =1
  • S0 =1 then P0 enter into the critical section
  • print '0'

Maximum no. of time 0 printed is thrice when execute in this order (p0 -> p1 -> p0 -> p2 -> p0)

So, At least twice will process P0 print ‘0’

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

...