2 ms·
Thanks for the tremendous detail on this point. Could you or someone else please give a minimal example of an undefined access in C, just so that I can be sure
by schoen 7y ago
Thanks for the tremendous detail on this point.
Could you or someone else please give a minimal example of an undefined access in C, just so that I can be sure of whether we're talking about the same phenomena here?
- jcranmer 7y agoA minimal program (using C11 threads): #include <threads.h> int x; int do_thread(void *) { for (int i = 0; i < 10000; i++) x = i; return 0; } int main() { thrd_t t; thrd_create(&t, do_thread, NULL); do_thread(NULL); thrd_join(&t, NULL); return 0; } There is an undefined data race on x, since it is simultaneously accessed from two threads without any synchronization. Replace the declaration of x with `_Atomic int x;`, and the resulting code is well-defined.