Blame src/functional/tls_init.c
|
nsz |
462b4f |
#include <pthread.h>
|
|
nsz |
462b4f |
#include "test.h"
|
|
nsz |
462b4f |
|
|
nsz |
462b4f |
__thread int tls_fix = 23;
|
|
nsz |
462b4f |
__thread int tls_zero;
|
|
nsz |
462b4f |
|
|
nsz |
462b4f |
static void *f(void *arg)
|
|
nsz |
462b4f |
{
|
|
nsz |
462b4f |
if (tls_fix != 23)
|
|
nsz |
462b4f |
error("fixed init failed: want 23 got %d\n", tls_fix);
|
|
nsz |
462b4f |
if (tls_zero != 0)
|
|
nsz |
462b4f |
error("zero init failed: want 0 got %d\n", tls_zero);
|
|
nsz |
462b4f |
tls_fix++;
|
|
nsz |
462b4f |
tls_zero++;
|
|
nsz |
462b4f |
return 0;
|
|
nsz |
462b4f |
}
|
|
nsz |
462b4f |
|
|
nsz |
462b4f |
#define CHECK(f) do{ if(f) error("%s failed.\n", #f); }while(0)
|
|
nsz |
462b4f |
#define length(a) (sizeof(a)/sizeof*(a))
|
|
nsz |
462b4f |
|
|
nsz |
462b4f |
int main()
|
|
nsz |
462b4f |
{
|
|
nsz |
462b4f |
pthread_t t[5];
|
|
nsz |
462b4f |
int i, j;
|
|
nsz |
462b4f |
|
|
nsz |
462b4f |
if (tls_fix != 23)
|
|
nsz |
462b4f |
error("fixed init failed: want 23 got %d\n", tls_fix);
|
|
nsz |
462b4f |
if (tls_zero != 0)
|
|
nsz |
462b4f |
error("zero init failed: want 0 got %d\n", tls_zero);
|
|
nsz |
462b4f |
|
|
nsz |
462b4f |
for (j = 0; j < 2; j++) {
|
|
nsz |
462b4f |
for (i = 0; i < length(t); i++) {
|
|
nsz |
462b4f |
CHECK(pthread_create(t+i, 0, f, 0));
|
|
nsz |
462b4f |
tls_fix++;
|
|
nsz |
462b4f |
tls_zero++;
|
|
nsz |
462b4f |
}
|
|
nsz |
462b4f |
for (i = 0; i < length(t); i++)
|
|
nsz |
462b4f |
CHECK(pthread_join(t[i], 0));
|
|
nsz |
462b4f |
}
|
|
nsz |
462b4f |
|
|
nsz |
462b4f |
return test_status;
|
|
nsz |
462b4f |
}
|