Skip to content

Instantly share code, notes, and snippets.

@hongruiqi
Last active November 29, 2015 14:44
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 hongruiqi/8572c68011287a8ce9b7 to your computer and use it in GitHub Desktop.
Save hongruiqi/8572c68011287a8ce9b7 to your computer and use it in GitHub Desktop.
test
#include <stdio.h>
#include <string.h>
#include <pthread.h>
int x;
int y;
int a;
int b;
void* f1(void* arg)
{
y = 1;
a = x;
return NULL;
}
void* f2(void* arg)
{
x = 1;
b = y;
return NULL;
}
int main()
{
while (1) {
x = y = 0;
a = b = -1;
pthread_t t1, t2;
pthread_create(&t1, NULL, f1, NULL);
pthread_create(&t2, NULL, f2, NULL);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
if (a == 0 && b == 0) {
puts("Hello world!");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment