jeudi 21 février 2019

Does modification order contribute to happens-before relationship?

// Thread 1
// do A
x.store(1, std::memory_order_release); // operation1

// Thread 2
// do B
x.store(2, std::memory_order_release); // operation2

// Thread 3
x.load(std::memory_order_acquire); // operation3

I've understood that if thread3 reads the value written by thread1, the release and acquire operations are synchronized-with, and effect of A is visible to thread3.
But what if the case is that:

  • the modification order for x is 1, 2
  • thread3 reads the value written by thread2, thus 2 happens-before 3.

Is there happens-before relationship between 1 and 3 ?
or intrinsically, does modification order contribute to happens-before relationship ?

Aucun commentaire:

Enregistrer un commentaire