Last active
August 3, 2021 13:28
-
-
Save heiher/c96802f7f6dee5956c22b4f8788eb8ad to your computer and use it in GitHub Desktop.
Test for reads from the same address out of order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <pthread.h> | |
static volatile unsigned long s; | |
static void * | |
write_handler (void *data) | |
{ | |
for (;;) { | |
unsigned long v; | |
v = s; | |
v += 1; | |
if (!v) { | |
exit (0); | |
break; | |
} | |
s = v; | |
} | |
return NULL; | |
} | |
int | |
main (int argc, char *argv[]) | |
{ | |
pthread_t th; | |
pthread_create (&th, NULL, write_handler, NULL); | |
for (;;) { | |
unsigned long a, b; | |
a = s; | |
b = s; | |
if (a > b) { | |
printf ("a > b %lu %lu !!!!\n", a, b); | |
break; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment