Skip to content

Instantly share code, notes, and snippets.

@heiher
Last active August 3, 2021 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heiher/c96802f7f6dee5956c22b4f8788eb8ad to your computer and use it in GitHub Desktop.
Save heiher/c96802f7f6dee5956c22b4f8788eb8ad to your computer and use it in GitHub Desktop.
Test for reads from the same address out of order
#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