3,387 views
4 votes
4 votes
A Binary semaphore variable mutex is initialized to '1' and the various binary semaphore operations like 9P(), 14V(), 6P(), 8V(), 3P(), 2V() are performed, then what is the present(final) value of the binary semaphore mutex?

4 Answers

12 votes
12 votes
Answer-0.

S=1(initialy)

After 9p() 1process get into critical section and other 8 process are in the waiting queue. Making s=0

Now becoz of 14v() 8 process get critical section and 9thv() update s=1 and from 10th v() to 14th v() s=1 becoz nobody is in the waiting queue.

Now becoz of 6p() 1 process get critical section making s=0 and 5 process put into the waiting queue.

Now becoz of 8v() 5process (which are in the waiting queue )get the critical section and 6th v() update s=1 and from  7th and 8th v() s=1 becoz nothing in queue.

Again 3p() ,1 process get critical section make s=0,two process(p2,p2) put into the waiting queue.

Now 2v(),1st v() help p1 to get critical section but s=0, and 2nd v() help p2 to get critical section and S=0 and if 1 more v() come then s=1 but here only 2v() therefore answer =0
2 votes
2 votes
Here answer is 1

initial value of S = 1

then we have   9P(), 14V(), 6P(), 8V(), 3P(), 2V()

9P() will change S=0 (only one 1 down operation will take place and remaining will be blocked).
similarly, 14V() changes S = 1
6P() changes  S= 0
8V() changes S = 1
3P() changes  S= 0
2V() changes  S = 1 answer
1 votes
1 votes
Binary semaphore has only two values 0 and 1

1 => process allowed to enter CS

0=> process put in waiting queue

if we perform any number of V operation its max value is 1

if initial value is 0 , and process executing P operation then that process is added in waiting queue
0 votes
0 votes
the answer would be 0. We will consider the no of blocked processes also.

Related questions

0 votes
0 votes
4 answers
3
piyushkr asked Jan 21, 2016
1,562 views
Up(Semaphore S) { if (Suspended list() is empty) S.value=1; else { Select a process from the suspended list and WakeUp() } }
0 votes
0 votes
0 answers
4
Arjun asked Feb 27, 2022
308 views
This is part of the site features explanation videos contest as explained here