1#include <pthread.h> 2#include "test.h" 3 4__thread int tls_fix = 23; 5__thread int tls_zero; 6 7static void *f(void *arg) 8{ 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; 16} 17 18#define CHECK(f) do{ if(f) t_error("%s failed.\n", #f); }while(0) 19#define length(a) (sizeof(a)/sizeof*(a)) 20 21int main() 22{ 23 pthread_t t[5]; 24 int i, j; 25 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); 30 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++; 36 } 37 for (i = 0; i < length(t); i++) 38 CHECK(pthread_join(t[i], 0)); 39 } 40 41 return t_status; 42} 43