Please fully trace through the program and explain how you arrive at each possib
ID: 3717608 • Letter: P
Question
Please fully trace through the program and explain how you arrive at each possible outcome
Consider the following program segments for two different processes (P1, P2) executing concurrently, where a and b are not shared variables, but x starts at zero and is a shared variable:
Case 1:
"Processor #1 "
for (a = 1; a <= 3; a++)
x = x + 1;
"Processor #2"
for (b = 1; b <= 3; b++)
x = x + 1;
If the processes P1 and P2 execute only once at any speed, what are the possible resulting values of x in Case 1 and Case 2? Explain your answers.
Explanation / Answer
Solution:
If they are preempted each time to run alternatively then the final value of x will be
6
In the given scenario the final value of x is always going to be 6 since if one process is preempting another then also they will be executed completely one way or another.
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)