12 static __thread
int local
;
14 extern __thread
int static_extern
;
15 extern __thread
int so_extern
;
17 /* deliberate failure */
18 static int *test_race(void)
23 static int *test_local(void)
28 static int *test_global(void)
33 static int *test_static_extern(void)
35 return &static_extern
;
38 static int *test_so_extern(void)
43 static const struct timespec awhile
= { 0, 200000000 };
45 typedef int *(*func_t
)(void);
49 char pad
[2 * (8 - sizeof(void*))];
51 static void *tls_ptr(void *p
)
53 struct testcase
*test
= (struct testcase
*)p
;
54 int *ip
= (*test
->func
)();
58 for(i
= 0; i
< COUNT
; i
++) {
62 printf("tls_ptr: case \"%s\" has mismatch: *ip=%d here=%d\n",
64 nanosleep(&awhile
, 0);
70 int *test_so_extern(void);
71 int *test_so_local(void);
72 int *test_so_global(void);
74 static const struct testcase tests
[] = {
75 #define T(t) { #t, test_##t }
86 #define NTESTS (sizeof(tests)/sizeof(*tests))
90 pthread_t threads
[NTESTS
*2];
95 for(i
= 0; i
< NTESTS
; i
++) {
96 pthread_create(&threads
[curthread
++], NULL
, tls_ptr
, (void *)&tests
[i
]);
97 pthread_create(&threads
[curthread
++], NULL
, tls_ptr
, (void *)&tests
[i
]);
100 for(i
= 0; i
< curthread
; i
++)
101 pthread_join(threads
[i
], NULL
);
108 printf("FAILED: no compiler support for __thread\n");