-
Consider the following code fragment :
if (fork () = =)
{a = a + 5, print f (“%d, %d\n”, a, &a),}
else {a = a – 5, print f (“%d, %d\n”, a, &a),}
Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is true?
-
- u = x + 10 and v = y
- u = x + 1 and v ≠ y
- u + 10 = x and v = y
- u + 10 = x and v ≠ y
- u = x + 10 and v = y
Correct Option: C
In the given program the output is :
⚈ 95 is printed by parent : u
⚈ 105 is printed by child : x
⇒ u + 10 = x
The logical addresses remain the same between the parent and child processes. Static Single Assignment is used for intermediate code in compiler design. In Static Single Assignment form(SSA) each assignment to a variable should be specified with distinct names. We use subscripts to distinguish each definition of variables. In the given code segment, there are two assignments of the variable x.
x = u – t;
x = y + w;
and three assignments of the variable y.
y = x * v;
y = t – z;
y = x * y
So we use two variables x1, x2 for specifying distinct assignments of x and y1, y2 and y3 each assignment of y. So, total number of variables is 10 (x1, x2, y1, y2, y3, t, u, v, w, z).
Static Single Assignment form(SSA) of the given code segment is:
x1 = u – t;
y1 = x1 * v;
x2 = y1 + w;
y2 = t – z;
y3 = x2 * y2;
Hence answer should be u + 10 = x and v = y