# Sample Final/Problem04

Problem 4. [10 points] Parallel Processing

A shared-memory system with two processors is executing the following two code fragments in parallel (one on each processor). All variables are shared and are initially zeros. The system uses sequential consistency.

Processor P0

``````A=10;
Atmp=A;
B=Atmp-2;
while(C==0);
C=6;
printf(“%d %d %d\n”,A,B,C);
``````

Processor P1

``````Btmp=B;
C=Btmp;
if(C==0)
C=3;
A=3;
``````

(A) [2 points] Is it possible for the printout in P0 to be “10 8 6”. If yes, show the execution interleaving that produces this printout. If no, explain why not.

(B) [2 points] Is it possible for P0 to get stuck and never print out anything? If yes, show the execution interleaving that produces this situation. If no, explain why not.

(C) [2 points] Is it possible for P0 to print 3 as the value of C? If yes, show the execution interleaving that produces this printout. If no, explain why not.

(D) [2 points] Is it possible for P0 to print a value of C other than 3 or 6? If yes, show the execution interleaving that produces this printout. If no, explain why not.

(E) [2 points] Is it possible for P0 to print a value of B other than 8? If yes, show the execution interleaving that produces this printout. If no, explain why not.