1 /* $FreeBSD$ */ 2 3 #include <stdio.h> 4 #include <pthread.h> 5 6 int __thread i; 7 8 void * 9 foo1(void *arg) 10 { 11 printf("thread %p, &i = %p\n", pthread_self(), &i); 12 for (i = 0; i < 10; i++) { 13 printf("thread %p, i = %d\n", pthread_self(), i); 14 sleep(1); 15 } 16 } 17 18 void * 19 foo2(void *arg) 20 { 21 printf("thread %p, &i = %p\n", pthread_self(), &i); 22 for (i = 10; i > 0; i--) { 23 printf("thread %p, i = %d\n", pthread_self(), i); 24 sleep(1); 25 } 26 } 27 28 int main(int argc, char** argv) 29 { 30 pthread_t t1, t2; 31 32 pthread_create(&t1, 0, foo1, 0); 33 pthread_create(&t2, 0, foo2, 0); 34 pthread_join(t1, 0); 35 pthread_join(t2, 0); 36 } 37