lundi 27 juillet 2020

The effect of memory barriers on data visibility to other threads

When a thread, T, reads an object at any point in time, the value it sees could be:

  1. The initial value of the object.
  2. A value stored by T.
  3. A value stored by another thread.

And there are memory barriers (Load-Load, Load-Store, Store-Load, and Store-Store), which can be defined as:

<Loads|Stores> before the barrier can't be reordered past the barrier and <Loads|Stores> after the barrier can't get reordered prior to the barrier.

Now, assume that a thread T1 is executing this piece of code:

load(X)
store(Y, 1)
-----------  <-- a barrier
load(Y)
store(X, 1)

while another thread, T2, is executing this piece of code:

load(X)
load(Y)

What would be the effect of the barrier in T1 on the visibility of X and Y to thread T2, when the barrier is:

  1. Load-Load
  2. Load-Store
  3. Store-Load
  4. Store-Store

Thanks!

Aucun commentaire:

Enregistrer un commentaire