This is a multipart blog article series, and in this series I am going to explain you the concepts of operating system. This article series is divided into multiple modules and this is the third module which consists of 10 articles.
In this we will see a question on binary semaphore and try to understand the concept of binary semaphore.
Question: What is the maximum number of processes that may present in critical section at any point of time?
Each process from P1-P9 will execute this code
Process P10 will execute this code
The initial value of mutex = 1
All processes P1-P10 are cooperative process
- Here, when
P1try to enter the critical section then it will run the first code. After executing the code the it get successfully and enter critical section. Now as the value of mutex is
0no other process can enter the critical section if they try to enter they will be sent to suspended list and get blocked.
- This is happening because, to enter the critical section, they have to execute the
P()operation which reduce the value of mutex from
0, but the value of mutex is already
P1has earlier executed it.
- So process from
P2- P9cannot enter the critical section, while
- Now, we will try to send
P10in the critical section, for that
P10will execute second code, and in that
v()operation will make value of mutex from
1and thus successfully get inside the critical section. Now, we have
P10in the critical section with the value of mutex
- And again
P2will try to enter the critical section, but because now the value of mutex is
1it will successfully get inside of critical section.
- Now we have
P2inside the critical section. And all the other processes from
P3-P9cannot enter the critical section.
- BUT THIS IS WRONG ANSWER.
- We can do one thing, if
P10exit the critical section then the value of mutex will become
P3can enter the critical section, now mutex value is
0, we will execute the second code and again the
P10will enter the critical section. Thus now we have four processes inside the critical section (P1, P2, P3 and P10).
- This will keep happening and at the end we will have
10process inside the critical section, and all of this is happening because
v()operation at the entry section. And we know that
v()operation increase the value from
1and if it is
1then it remains
Therefore, the final answer is
10 processes (P1, P2, P3, P4, P5, P6, P7, P8, P9, and P10)
So this was all about question on binary semaphore. Hope you liked it and learned something new from it.
If you have any doubt, question, quires related to this topic or just want to share something with me, then please feel free t o contact me.