Redirected
recategorized
2,380 views
2 votes
2 votes

There are three processes $P_{1}, P_{2}$ and $P_{3}$ sharing a semaphore for synchronizing a variable. Initial value of semaphore is one. Assume that negative value of semaphore tells us how many processes are waiting in queue. Processes access the semaphore in following order :

  1. $P2$ needs to access
  1. $P1$ needs to access
  1. $P3$ needs to access
  1. $P2$ exits critical section
  1. $P1$ exits critical section

The final value of semaphore will be :

  1. $0$
  2. $1$
  3. $-1$
  4. $-2$
recategorized

5 Answers

Best answer
5 votes
5 votes

initial value of semaphores S=1

  1. P2 needs to access decreases it to 0    (no one is waiting)
  2. P1 needs to access decreases it to -1   (one process is waiting)
  3. P3 needs to access decreases it to -2 ( 2 process r waiting)
  4. P2 exits critical section increases it to -1 ( one process is waiting)
  5. Pi exits critical section increases it to 0   ( no process is waiting)                                                                                                                    so ans is A
selected by
1 votes
1 votes

Initially the value of semaphore S is 1.

After (a) S=0
(b) S=-1
(c) S= -2
(d) S= -1
(e) S= 0

  ans is A

0 votes
0 votes

Option 1

sem=1 => P2 accessed makes sem = 0

                P1 accessed makes sem=-1

               P3 accessed makes sem = -2

               P2 exits CS makes sem = -1 

                P1 exits CS makes sem = 0

Final sem = 0

Answer:

Related questions

1 votes
1 votes
5 answers
1
go_editor asked Mar 24, 2020
2,250 views
In a paging system, it takes $30$ ns to search translation Look-a-side Buffer (TLB) and $90$ ns to access the main memory. If the TLB hit ratio is $70\%$, the effective m...
1 votes
1 votes
4 answers
2
go_editor asked Mar 24, 2020
990 views
Match the following w.r.t Input/Output management :$\begin{array}{ll} &{\text{List – I}} & & {\text{List – II}} \\ \text{a.} & \text{Device controller} & \text{i.} &...
2 votes
2 votes
4 answers
3
go_editor asked Mar 24, 2020
4,540 views
Which of the following scheduling algorithms may cause starvation ?First-come-first-servedRound RobinPriorityShortest process nextShortest remaining time first a, c and e...