ttls2.c revision 256281
1/* $FreeBSD: stable/10/tools/regression/tls/ttls2/ttls2.c 133066 2004-08-03 09:04:01Z dfr $ */ 2 3#include <stdio.h> 4#include <pthread.h> 5 6int __thread i; 7 8void * 9foo1(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 18void * 19foo2(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 28int 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