Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why there is no data-race in the following case?

A data race occurs when two threads access the same variable concurrently and at least one of the accesses is a write.

https://isocpp.org/wiki/faq/cpp11-language-concurrency

// start with x==0 and y==0
if (x) y = 1;   // Thread 1 
if (y) x = 1;   // Thread 2 

Is there a problem here? More precisely, is there a data race? (No there isn’t).

Why does the original article claim that there is no data race here?

like image 664
q0987 Avatar asked Feb 11 '17 18:02

q0987


1 Answers

Neither thread will be writing since neither variable is non-zero before the conditionals.

like image 183
Louis Langholtz Avatar answered Oct 04 '22 23:10

Louis Langholtz