in Operating System
245 views
1 vote
1 vote

Consider the following segment:

Note : Assume the count = count + 1; will execute in ‘3’ different instructions.

Where, m[count] refers to memory value of count variable.

Preemption can occur while executing the above instructions. Each of the tally function has a separate register allocated to it in which the value of count is stored. After completion of main function, what will be the minimum and maximum values of count in the end of the program?

a) Min = 5, Maximum = 15

b) Min = 2, Maximum = 15

c) Min = 1, Maximum = 15

d) Min = 15, Maximum = 15

in Operating System
245 views

2 Comments

edited by
option b?
0
0
0
0

1 Answer

0 votes
0 votes

Min:

To get minimum, we need to exhaust any 2 function calls and make the 3rd call update the count value. Basically make a function call win the race condition, such that the function updates the count variable with lowest possible value. This also means rest two function calls should lose the race.

 


 

Max is 15:
Assume no pre-emption at all. Let the function run one after the other. You get 15.

Related questions