|
Szabolcs Nagy |
08cb39 |
#include <pthread.h>
|
|
Szabolcs Nagy |
08cb39 |
#include <string.h>
|
|
Szabolcs Nagy |
08cb39 |
#include "test.h"
|
|
Szabolcs Nagy |
08cb39 |
|
|
Szabolcs Nagy |
cfa23c |
#define TESTC(c, m) ( (c) || (t_error("%s failed (" m ")\n", #c), 0) )
|
|
Szabolcs Nagy |
08cb39 |
#define TESTR(r, f, m) ( \
|
|
Szabolcs Nagy |
cfa23c |
((r) = (f)) == 0 || (t_error("%s failed: %s (" m ")\n", #f, strerror(r)), 0) )
|
|
Szabolcs Nagy |
08cb39 |
|
|
Szabolcs Nagy |
08cb39 |
static pthread_key_t k1, k2;
|
|
Szabolcs Nagy |
08cb39 |
|
|
Szabolcs Nagy |
08cb39 |
static void dtor(void *p)
|
|
Szabolcs Nagy |
08cb39 |
{
|
|
Szabolcs Nagy |
08cb39 |
*(int *)p = 1;
|
|
Szabolcs Nagy |
08cb39 |
}
|
|
Szabolcs Nagy |
08cb39 |
|
|
Szabolcs Nagy |
08cb39 |
static void *start(void *arg)
|
|
Szabolcs Nagy |
08cb39 |
{
|
|
Szabolcs Nagy |
08cb39 |
int *p = arg;
|
|
Szabolcs Nagy |
08cb39 |
if (pthread_setspecific(k1, p) || pthread_setspecific(k2, p+1))
|
|
Szabolcs Nagy |
08cb39 |
return arg;
|
|
Szabolcs Nagy |
08cb39 |
return 0;
|
|
Szabolcs Nagy |
08cb39 |
}
|
|
Szabolcs Nagy |
08cb39 |
|
|
Szabolcs Nagy |
08cb39 |
int main(void)
|
|
Szabolcs Nagy |
08cb39 |
{
|
|
Szabolcs Nagy |
08cb39 |
pthread_t td;
|
|
Szabolcs Nagy |
08cb39 |
int r;
|
|
Szabolcs Nagy |
08cb39 |
void *res;
|
|
Szabolcs Nagy |
08cb39 |
int foo[2], bar[2];
|
|
Szabolcs Nagy |
08cb39 |
|
|
Szabolcs Nagy |
08cb39 |
/* Test POSIX thread-specific data */
|
|
Szabolcs Nagy |
08cb39 |
TESTR(r, pthread_key_create(&k1, dtor), "failed to create key");
|
|
Szabolcs Nagy |
08cb39 |
TESTR(r, pthread_key_create(&k2, dtor), "failed to create key");
|
|
Szabolcs Nagy |
08cb39 |
foo[0] = foo[1] = 0;
|
|
Szabolcs Nagy |
08cb39 |
TESTR(r, pthread_setspecific(k1, bar), "failed to set tsd");
|
|
Szabolcs Nagy |
08cb39 |
TESTR(r, pthread_setspecific(k2, bar+1), "failed to set tsd");
|
|
Szabolcs Nagy |
08cb39 |
TESTR(r, pthread_create(&td, 0, start, foo), "failed to create thread");
|
|
Szabolcs Nagy |
08cb39 |
TESTR(r, pthread_join(td, &res), "failed to join");
|
|
Szabolcs Nagy |
08cb39 |
TESTC(res == 0, "pthread_setspecific failed in thread");
|
|
Szabolcs Nagy |
08cb39 |
TESTC(foo[0] == 1, "dtor failed to run");
|
|
Szabolcs Nagy |
08cb39 |
TESTC(foo[1] == 1, "dtor failed to run");
|
|
Szabolcs Nagy |
08cb39 |
TESTC(pthread_getspecific(k1) == bar, "tsd corrupted");
|
|
Szabolcs Nagy |
08cb39 |
TESTC(pthread_getspecific(k2) == bar+1, "tsd corrupted");
|
|
Szabolcs Nagy |
08cb39 |
TESTR(r, pthread_setspecific(k1, 0), "failed to clear tsd");
|
|
Szabolcs Nagy |
08cb39 |
TESTR(r, pthread_setspecific(k2, 0), "failed to clear tsd");
|
|
Szabolcs Nagy |
08cb39 |
TESTR(r, pthread_key_delete(k1), "failed to destroy key");
|
|
Szabolcs Nagy |
08cb39 |
TESTR(r, pthread_key_delete(k2), "failed to destroy key");
|
|
Szabolcs Nagy |
cfa23c |
return t_status;
|
|
Szabolcs Nagy |
08cb39 |
}
|