12546665aSDoug Rabson
22546665aSDoug Rabson #include <pthread.h>
3*75743a83SEnji Cooper #include <stdio.h>
4*75743a83SEnji Cooper #include <unistd.h>
52546665aSDoug Rabson
62546665aSDoug Rabson int __thread i;
72546665aSDoug Rabson
82546665aSDoug Rabson void *
foo1(void * arg)92546665aSDoug Rabson foo1(void *arg)
102546665aSDoug Rabson {
112546665aSDoug Rabson printf("thread %p, &i = %p\n", pthread_self(), &i);
122546665aSDoug Rabson for (i = 0; i < 10; i++) {
132546665aSDoug Rabson printf("thread %p, i = %d\n", pthread_self(), i);
142546665aSDoug Rabson sleep(1);
152546665aSDoug Rabson }
16*75743a83SEnji Cooper return (NULL);
172546665aSDoug Rabson }
182546665aSDoug Rabson
192546665aSDoug Rabson void *
foo2(void * arg)202546665aSDoug Rabson foo2(void *arg)
212546665aSDoug Rabson {
222546665aSDoug Rabson printf("thread %p, &i = %p\n", pthread_self(), &i);
232546665aSDoug Rabson for (i = 10; i > 0; i--) {
242546665aSDoug Rabson printf("thread %p, i = %d\n", pthread_self(), i);
252546665aSDoug Rabson sleep(1);
262546665aSDoug Rabson }
27*75743a83SEnji Cooper return (NULL);
282546665aSDoug Rabson }
292546665aSDoug Rabson
30*75743a83SEnji Cooper int
main(int argc,char ** argv)31*75743a83SEnji Cooper main(int argc, char** argv)
322546665aSDoug Rabson {
332546665aSDoug Rabson pthread_t t1, t2;
342546665aSDoug Rabson
352546665aSDoug Rabson pthread_create(&t1, 0, foo1, 0);
362546665aSDoug Rabson pthread_create(&t2, 0, foo2, 0);
372546665aSDoug Rabson pthread_join(t1, 0);
382546665aSDoug Rabson pthread_join(t2, 0);
39*75743a83SEnji Cooper
40*75743a83SEnji Cooper return (0);
412546665aSDoug Rabson }
42