ttls2.c revision 292142
1/* $FreeBSD: stable/10/tools/regression/tls/ttls2/ttls2.c 292142 2015-12-13 03:45:57Z ngie $ */ 2 3#include <pthread.h> 4#include <stdio.h> 5#include <unistd.h> 6 7int __thread i; 8 9void * 10foo1(void *arg) 11{ 12 printf("thread %p, &i = %p\n", pthread_self(), &i); 13 for (i = 0; i < 10; i++) { 14 printf("thread %p, i = %d\n", pthread_self(), i); 15 sleep(1); 16 } 17 return (NULL); 18} 19 20void * 21foo2(void *arg) 22{ 23 printf("thread %p, &i = %p\n", pthread_self(), &i); 24 for (i = 10; i > 0; i--) { 25 printf("thread %p, i = %d\n", pthread_self(), i); 26 sleep(1); 27 } 28 return (NULL); 29} 30 31int 32main(int argc, char** argv) 33{ 34 pthread_t t1, t2; 35 36 pthread_create(&t1, 0, foo1, 0); 37 pthread_create(&t2, 0, foo2, 0); 38 pthread_join(t1, 0); 39 pthread_join(t2, 0); 40 41 return (0); 42} 43