mercredi 20 décembre 2017

Possible data race between writes to the same address in memory

Consider the following snippet.

T data;
T* ptr1 = &data;
T* ptr2 = &data;
*ptr1 = ...;
std::thread thread([ptr2]() {
    *ptr2 = ...;
});
thread.join();

Question: does it introduce a data race?

My thoughts: since ptr1 and ptr2 are different variables, the assignment and the capture-by-value are subject to reordering. Thus, the data race is there.

Is this correct?

Aucun commentaire:

Enregistrer un commentaire