add test for strftime
[libc-test.git] / src / functional / tls_init.c
blobd8b6e8f82fed73be11bbf183c2f3c6d2285955b6
1 #include <pthread.h>
2 #include "test.h"
4 __thread int tls_fix = 23;
5 __thread int tls_zero;
7 static void *f(void *arg)
9 if (tls_fix != 23)
10 t_error("fixed init failed: want 23 got %d\n", tls_fix);
11 if (tls_zero != 0)
12 t_error("zero init failed: want 0 got %d\n", tls_zero);
13 tls_fix++;
14 tls_zero++;
15 return 0;
18 #define CHECK(f) do{ if(f) t_error("%s failed.\n", #f); }while(0)
19 #define length(a) (sizeof(a)/sizeof*(a))
21 int main()
23 pthread_t t[5];
24 int i, j;
26 if (tls_fix != 23)
27 t_error("fixed init failed: want 23 got %d\n", tls_fix);
28 if (tls_zero != 0)
29 t_error("zero init failed: want 0 got %d\n", tls_zero);
31 for (j = 0; j < 2; j++) {
32 for (i = 0; i < length(t); i++) {
33 CHECK(pthread_create(t+i, 0, f, 0));
34 tls_fix++;
35 tls_zero++;
37 for (i = 0; i < length(t); i++)
38 CHECK(pthread_join(t[i], 0));
41 return t_status;