Questions / Quant development, Concurrency & coordination

Enumerate a sequentially consistent store-buffer test

Challenge, about 10 minutes. Question D231.

x and y start at zero. Every displayed operation is sequentially consistent, and each thread preserves program order. How many distinct pairs (r1,r2) are possible?

// Thread A
x.store(1);
r1 = y.load();
// Thread B
y.store(1);
r2 = x.load();

Answer it in the app It's free. You get hints, a second try if you miss, and a follow-up question.

Show the answer and worked solution

Answer: 3 pairs

  1. The possible pairs are (0,1), (1,0), and (1,1). Pair (0,0) would require an impossible cycle in the total order.

Interview shortcut. Store-buffer litmus under SC: (0,0) is impossible.

In the app this has a follow-up where one thing about the setup changes. Try the follow-up.

More concurrency & coordination questions