The program isn't clear to me. I guess you want something like this: int x; volatile int v;
CPU1: write(x, 1) (1) write(v, 1) (2) CPU2 read(v) (3) read(x) (4) Then there exists an execution where (4) sees value written by (1) it is in a data race with. E.g. (1)->(3)->(4). So since the program has at least 1 execution with a data race. So your observation that the program is not data race free, is correct. To resolve the data race, you want to do something like this: int x; volatile int v; CPU1: write(x, 1) (1) write(v, 1) (2) CPU2 if(read(v)==1){ (3) print(read(x)); (4) } When (3) has observed the value written by (2) there is a happens-before edge between (2) and (3). And due to the program order between (1)/(2) and (3)/(4) and the transitive nature of happens-before, there is a happens-before edge between (1) and (4). So the value'1' should be printed. This program is data race free. On Sun, Oct 23, 2022 at 7:59 PM r r <grosi...@gmail.com> wrote: > int x; > volatile int v; > > write(x, 1) read(v) > write(v, 1) read(x) > > Is that program data race free? On my eye it is not not because there is > an execution that write(x, 1) and read(x) are not in happens-before > relationship. > > -- > You received this message because you are subscribed to the Google Groups > "mechanical-sympathy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to mechanical-sympathy+unsubscr...@googlegroups.com. > To view this discussion on the web, visit > https://groups.google.com/d/msgid/mechanical-sympathy/9a25a145-5271-4f7a-ad3d-3633367becd4n%40googlegroups.com > <https://groups.google.com/d/msgid/mechanical-sympathy/9a25a145-5271-4f7a-ad3d-3633367becd4n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "mechanical-sympathy" group. To unsubscribe from this group and stop receiving emails from it, send an email to mechanical-sympathy+unsubscr...@googlegroups.com. To view this discussion on the web, visit https://groups.google.com/d/msgid/mechanical-sympathy/CAGuAWdCCq8bLneYkLR%3D4Ddbjfk1dsJ8RrGx%3DyPgssPvzYKuQiw%40mail.gmail.com.