Path: blob/main/tools/regression/tls/ttls2/ttls2.c
48255 views
1#include <pthread.h>2#include <stdio.h>3#include <unistd.h>45int __thread i;67void *8foo1(void *arg)9{10printf("thread %p, &i = %p\n", pthread_self(), &i);11for (i = 0; i < 10; i++) {12printf("thread %p, i = %d\n", pthread_self(), i);13sleep(1);14}15return (NULL);16}1718void *19foo2(void *arg)20{21printf("thread %p, &i = %p\n", pthread_self(), &i);22for (i = 10; i > 0; i--) {23printf("thread %p, i = %d\n", pthread_self(), i);24sleep(1);25}26return (NULL);27}2829int30main(int argc, char** argv)31{32pthread_t t1, t2;3334pthread_create(&t1, 0, foo1, 0);35pthread_create(&t2, 0, foo2, 0);36pthread_join(t1, 0);37pthread_join(t2, 0);3839return (0);40}414243