Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test for reads from the same address out of order (5000)
#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 v[1000];
unsigned int i = 0;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
v[i++] = s;
for (i = 0; i < (1000 - 1); i++) {
if (v[i] > v[i + 1]) {
printf ("a > b %lu %lu !!!!\n", v[i], v[i + 1]);
return -1;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment