# Possible results of two programs running on a symmetric multicore system

This question is from Patterson and Hennessy's Computer Organization and Design.

Consider the following portions of two different programs running at the same time on four processors in a symmetric multicore processor (SMP). Assume that when this code is run, both $x$ and $y$ are 0.

Core 1: $x = 2$;

Core 2: $y = 2$;

Core 3: $x = x + 1$;

Core 4: $z = x + y$;

What are all the possible resulting values of $x$, $y$, and $z$? You will need to examine all possible interleaving of instructions.

The given answer is, for $(x, y, z)$: $(3, 2, 5), (3, 2, 4), (3, 2, 3), (3, 2, 2), (3, 2, 0), (2, 2, 4), (2, 2, 3), (2, 2, 2), (2, 2, 1), (2, 2, 0).$

I understand how $x$ is either 2 or 3 and why $y$ is forced to be 2, but I don't know how $z$ takes those values.

• Welcome to CS.SE! What have you tried? What are your thoughts? What values do you think $z$ can take on? What approaches have you considered, for figuring out the answer, and what happened when you tried following those approaches? Please edit your question to show your thoughts. We expect you to make every effort to solve it on your own before asking, and to show us in the question what you've tried/considered. – D.W. Dec 17 '15 at 21:16