Previous | Next --- Slide 10 of 52
Back to Lecture Thumbnails
blah329

This example assumes that we are in a system that upholds sequential consistency. This means that reads and writes cannot be reordered, and that a subsequent write/read must wait for the previous write/read to commit. There are 3 possible outputs for this program. It can either print "Hello", "world", or not output anything. In the case where "Hello" is printed, only "Hello" can be printed because P2 set B = 1, but since the system is sequentially consistent, the read to A and printing of "World" could not have happened yet. Even when it does happen, if "Hello" has been printed, then by the definition of sequential consistency, A must be 1, since the write to A came before the read from B. The case where "World" is printed is similar. When "World" is printed, by sequential consistency, this means that B has already been set to 1, so when P1 checks the value of B, it will see it as 1, and not print "Hello." Finally, in the case where nothing is printed, P1 can write to A and then P2 can write to B, or vice versa, and this will cause neither of one to enter the conditional statements.

POTUS

"Hello world" can never be printed because for "Hello" to be printed, B==0, which means that the "B=1" line on thread 2 has not be executed yet. If thread 2 were to run after "Hello" was printed, A!=0, and "world" can't be printed. The same applies for "world Hello".

jedi

From the perspective of speeding up exam taking, it helps to pay attention to symmetry. Since both threads are duals of each other, if "hello" can be printed, then so can "world". Similarly, once you compute that "hello world" cannot be printed, then neither can "world hello".

anonymous

Here, sequential consistency mechanism is applied which means we'll keep the order of W->R, W->W, R->W and R->R operation. Hence, for any of these two cores, the W operation must have been finished and observed by the other core when the R operation is carried out. In this way, no matter "Hello World" or "World Hello" cannot be printed.

unparalleled

If we relax the W->R ordering, the above execution can print "Hello World" or "World Hello" as well. Please correct me if I am wrong.

themj

The three strings that can be printed are: "", "Hello", and "World" since the write propagate immediately.