I think the example code in section "4. Reordering" would be stronger if one of the two threads had their order of operations switched, e.g.:
void thread_2()
{
printf("value_2: %d\n", *ptr_to_shared_2);
printf("value_1: %d\n", *ptr_to_shared_1);
}
That way, when you see: value_2: 1
value_1: 0
You know reordering must have happened. As it stands, no reordering is necessary -- it could simply be that both writes took effect at thread 2 in-order, but with the write to *ptr_to_shared_1 taking effect after the first print statement.
sammycage•2h ago