mercredi 29 septembre 2021

Does a single load synchronize with multiple stores?

The following is a quote from C++ Standard - Memory Order:

If an atomic store in thread A is tagged memory_order_release and an atomic load in thread B from the same variable is tagged memory_order_acquire, all memory writes (non-atomic and relaxed atomic) that happened-before the atomic store from the point of view of thread A, become visible side-effects in thread B. That is, once the atomic load is completed, thread B is guaranteed to see everything thread A wrote to memory.

The synchronization is established only between the threads releasing and acquiring the same atomic variable. Other threads can see different order of memory accesses than either or both of the synchronized threads.

Consider an atomic variable v and the following steps:

  1. Thread A stores in v using memory_order_release
  2. Thread B stores in v using memory_order_release
  3. Thread C loads from v using memory_order_acquire

Is the following statement true: "thread C is guaranteed to see everything thread A or B wrote to memory."

Aucun commentaire:

Enregistrer un commentaire