edited by
23,716 views
75 votes
75 votes

Given below is a program which when executed spawns two concurrent processes :
semaphore $X : = 0 ;$
/* Process now forks into concurrent processes $P1$ & $P2$ */

$\begin{array}{|l|l|}\hline \text{$P1$}  &  \text{$P2$}  \\\hline  \text{repeat forever } & \text{repeat forever} \\ \text{$V (X) ;$ } & \text{$ P(X) ;$} \\  \text{Compute;  } & \text{Compute;}\\  \text{$P(X) ;$  } & \text{$V(X) ;$} \\\hline \end{array}$

Consider the following statements about processes $P1$ and $P2:$

  1. It is possible for process $P1$ to starve.
  2. It is possible for process $P2$ to starve.

Which of the following holds?

  1. Both (I) and (II) are true.
  2. (I) is true but (II) is false.
  3. (II) is true but (I) is false
  4. Both (I) and (II) are false
edited by

11 Answers

8 votes
8 votes
Answer: A

I. Case: P1 will enter its critical section once at the beginning and then only P2 keeps on entering its critical section again and again. Thus, making P1 starve.

II. Case: P1 will enter its critical section once at the beginning and then only P1 keeps on entering its critical section again and again. Thus, making P2 starve.
7 votes
7 votes

Starvation describes a situation where a thread (or a process) is unable to gain regular access to shared resources and is unable to make progress. 

[Source : https://docs.oracle.com/javase/tutorial/essential/concurrency/starvelive.html ]

In the given question, $P2$ can't enter critical section (CS) unless $P1$ executes V(X) once. Thus, $P1$ stops progress of $P2$.  (Even when $P2$ wants to execute CS it can't do so). So, $P2$ can starve until $P1$ starts execution.

After $P1$ executes V(X), it enters CS and now $P2$ which was initially blocked on P(X) can also enter CS. Now, in this situation when both processes are in CS, even if $P1$ has completed it's execution it can't exit CS until $P2$ exits once. It gets blocked at P(X) until $P2$ executes V(X). Thus, here $P2$ stops progress of $P1$ and so, $P1$ can starve until $P2$ exits the CS.

 

$\therefore$   Ans is $(a)$.

3 votes
3 votes
I think no process will starve but mutual exclusion may not be possible.

And option D is correct.
As x is 0 process p1 will compute first. While p1 is in critical section(compute) x=1 then process p2 can execute p(x) and be in compute too.

Right or not??
Answer:

Related questions

61 votes
61 votes
8 answers
1