in Operating System edited by
441 views
0 votes
0 votes

In these type of questions “Will we NOT consider CONTEXT SWITCHING unless mentioned???”

If context switching is ALLOWED, minimum value will be 8...Correct me if I’m wrong.

in Operating System edited by
441 views

3 Comments

How it will be 8 when context switching is allowed ???
0
0
Read X = 0 by both the threads Thread1 and Thread2

Complete all the instructions of one thread except the last, i.e Thread2 runs the loop 15 times doing x = x+5, so just execute the first 14 and Store back the modified value of X. Since the initial value of X = 0 was read by both the threads, Thread1 still holds 0 for X.

Initiate the looping statement of Thread1. After running it for the first time X = 3, and store it back.

Now we have one last time for Thread2(Since we ran it for 14 times initially, instead for 15). Read X, i.e 3.

After reading the value of X by Thread2, complete the loop of Thread1.

Now in Thread2 increment X by 5 and Store it back. The final value of X thus obtained will be 8.
1
1
maximum value will be 285 .after thread1 completed its job then the value will be 75 after that thread 2 will execute then the value will become 285 .correct me where i am wrong????
0
0

Please log in or register to answer this question.

Related questions