Initial value of B is 2 //value stored in main memory

__Value of B = 4__

First execute P2()

P2 ( ) {

D = 2 * B; // 2 × 2 = 4

B = D – 1; // B = 4 – 1 = 3

}

write the value of B = 3 to memory

execute P1()

P1 ( ) {

C = B – 1; // C = 3 – 1 = 2

B = 2 * C; // B = 2 × 2 = 4

}

write the value of B = 4 is memory.

Distinct value of B is 4.

__Value of B =3 __

First Execute P1()

P1 ( ) {

C = B – 1; // C = 2 – 1 = 1

B = 2 * C; // B = 2 × 1 =2

}

write the value of B = 2 to memory

then execute P2()

P2 ( ) {

D = 2 * B; // 2 × 2 = 4

B = D – 1; // B = 4 – 1 = 3

}

write the value of B = 3 to memory

One of the distinct values of B is 3.

__Value of B = 2__

First execute P2()

P2 ( ) {

D = 2 * B; // 2 × 2 = 4

B = D – 1; // B = 4 – 1 = 3

}

//don’t write to memory

execute P1() // with initial value of B = 2

P1 ( ) {

C = B – 1; // C = 2 – 1 = 1

B = 2 * C; // B = 2 × 1 = 2

}

write the value B = 3 by P2() in memory.

overwrite the value written by P2() as B = 2 by P1() in memory.

One of the distinct values of B is 2.

Therefore, the distinct values of B are 2, 3 and 4.

The number of distinct values that B can possibly take after the execution is 3.