5,681 views
7 7 votes
Consider the following program:

Const int n= 10 
int Count= 0 
Void A( ) 
{ 
    int i; 
    for(i= 1 to n) 
    Count= Count + 1; 
} 

Main ( ) 
{ 
    Par begin 
A( ); 
A( ); 
A( ); 
A( ); 
    Par end 
    
}


5 What is the minimum and maximum possible value of count after the completion of the program?

(a) 1, 40                               (b) 2, 40

(c) 3, 40                               (d) 4, 40
 

2 Answers

27 27 votes

MIN = 2

MAX = 40

Maximum is obvious.

For Min -

Lets consider increment of count is in 3 micro instruction 

step 1  Load Ri M[count]

step 2 INCR Ri

step 3 M[count] Ri

Where Ri is the local register allocated by each function called and used for temporary storage.

Lets called   first A() is A1()

Second A() is A2()

Third A() is A3()

Fourth A() is A4().

Now every function from A1() to A4() will execute concurrently and each function will execute all 3 micro instruction; 

1> Now consider A1() call first, it increment COUNT from 0 to 1 in 3 micro instruction but after executing 2 micro instruction and gets preempted so at this time the value of R1(temprrary register ) = 1 but the count value will be still 0.

 2> Now let A2() and A3() complete the execution so count value will be 20.

3> A4() will start it execution and let it iterate for "9" times so the count value will be 29 and preempt the A4().

4> Let A1() will start it's execution and it will execute its 3 micro instruction and overwrite count value from 29 to 1 in it's first iteration and again preempt.

5> lets A4() start it's execution now the count value is 1 so it will iterate its 10 'th iteration and execute 2 micro instruction and then preempt A4(). at this time R4(temporary register = 2) and count = 1.

6> Now execute remaining iteration of A1 form i=2 to 10 so it will make count value as 10 and complete it's execution.

7>In final step A4() will start it's execution and will execute 3 micro instruction for 9'th iteration and overwrite count = 1 and in the 10 iteration it will increment count from 1 to 2 and finish the execution.

So Min = 2

Max = 40. 

11 11 votes

Option B --2,40 

Devid count=count+1 into lower lvl instruction..

​plz follow the fig...and correct me if I am wrong..Thanks..

Position:
Show:

Related questions

4 4 votes
0 0 answers
1.7k
1.7k views
atulcse asked Jan 19, 2022
1,698 views
Consider the following proposed solution to Dining Philosopher’s problem to avoid deadlock. The binary semaphore lock is initialized to 1.Which of the following is correc...
2 2 votes
1 1 answer
744
744 views
junaid ahmad asked Jan 20, 2018
744 views
States which of the statements are true and please give some reference :S1:Bounded waiting and progress implies no starvationS2:Bounded waiting doesn't imply starvation f...
3 3 votes
1 answers 1 answer
2.1k
2.1k views
srestha asked Oct 14, 2016
2,051 views
In process synchronozation , when we can say progress is satisfied and when progress not satisfied?Explain with example.(Donot give just definition, need clear difference...
4 4 votes
1 1 answer
272
272 views
GO Classes asked Jul 25
272 views
Which of the following statements are correct?Mutual exclusion ensures that if one process is executing in its critical section, no other process can execute in its criti...