Last active
November 29, 2015 14:44
-
-
Save hongruiqi/8572c68011287a8ce9b7 to your computer and use it in GitHub Desktop.
test
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 <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