2.3k views
1. Four jobs are waiting to be run. Their expected run times are $6, 3, 5$ and $x.$ In what order should they be run to minimize the average response time?
2. Write a concurrent program using $\text{par begin-par end}$ to represent the precedence graph shown below.

edited | 2.3k views
+1
there is difference between par begin par end and co begin end???

1. Here, all we need to do for minimizing response time is to run jobs in increasing order of burst time.
2. Schedule shorter jobs first, which will decrease the waiting time of longer jobs, and consequently average waiting time and average response time decreases.

3. $6, 3, 5$ and $x.$

If $X < 3 < 5 <$6,  then order should be $x,3,5,6$

If $3 < 5 < 6 < x$, then order is $3,5,6,x$.

If $3 < x < 5 < 6$, then order is $3,x,5,6.$  If $5 < x < 6$, then order is $3,5,x,6.$

Idea is that if you have $S_1 \to S_2$ then you create new semaphore a, assume that initial value of all semaphores is $0$. Then $S_2$ thread will invoke $P(a)$ & will get blocked. When $S_1$ get executed, after that it'll do $V(a)$ which will enable $S_2$ to run. Do like this for all edges in graph.
Let me write program for it.

Begin

Semaphores $a,b,c,d,e,f,g$

ParBegin $S_1 V(a) V(b) V(c) V(d)$ Parend
ParBegin $P(a) S_2 V( e)$ Parend
ParBegin $P(b) S_3 V(f)$ Parend
ParBegin $P( c) P( e) S_4 V(g)$ Parend
ParBegin $P(d) P(f) P(g) S_5$ Parend
End

IF you reverse engineer this program you can get how this diagram came.

Parbegin Parend – Parallel execution

$P-$ Down, $V-$ Up

edited
+1
co and par are same ?? what is meaning of co
+6
co - concurrent

par-  parallel

I think they are same.
+1
ok... par begin p(g)p(f)p(d) s5 rt ?
+1
okay now ?
+2

I think u have misplaced/interchanged the use of Parbegin & begin here..Becoz

ParBegin  S1 V(a) V(b) V(c) V(d) Parend

&

ParBegin P(a) S2 V( e) Parend

can execute parallely .But u hv placed them inside begin meaning they execute one by one..

+15
As it is not mentioned that algoritm must be non preemptive so Round Robin with TQ = 1 is the best approach here.
+1
@Akash , What is the use of c and d semaphore here? I think you have used them because of the edges in the precedence graph s1 to s4 and s1 to s5. But are not these extra (I mean unnecessary)?
+1
@ Akash Kanase, @Bikram Ballav Sir, @Hemant Parihar, I feel Himanshu 1 says it correct. Could you please crosscheck it once.
+1
@himanshu

I too think the same.
0
S1
par-begin
begin
S2
S4
end
S3
par-end
S5


Is this code right?

24) a. It will depends on value of x.. U can decide others 3 process sequence I.e 3,5,6 Now x can come anywhere depending on its value.. Remember we shld gve it in increasing order to minimize response time
The average response time depends upon the value of x

if x < 3

then the order is x,3,5,6

if the value of x >3 and x < 5

the the order is 3,x,5,6

if the value of x > 5 and x < 6

then the order is 3,5,x,6,

if the order > 6

then the order is

3,5,6,x

For the second question it will be S1---S2---S3---S4---S5  OR S1---S3----S2----S4----S5
+8
I have doubt..

Response time is defined as the time taken from submission of request to the first response by the CPU.

So, cant we just use round robin with time quantum = 1. This way each process will use the cpu for the first time after (0,1,2,3) secs respectivly..! Making the average response time = (0+1+2+3) / 4.
+4
@Harsh181996 I do think the same. Because minimum average time is always obtained by Round Robin and it is nowhere mentioned in question that the algorithm is non-preemptive.

Above answers are valid only when algorithm is supposed to be non- preemptive
+1

what will be the value of x by this ?

+1
Whatever be the value of x, the avg. response time will not change if we do RR scheduling with time quantum 1.
0

It is very valid question put up by Harsh181996 but I think if we had used the round robin algo then there wouldn't have been any interest in finding the order of execution of the processes as any order will give the same average RT. So the purpose of the question might get lost.

1
2