5 #define TESTC(c, m) ( (c) || (t_error("%s failed (" m ")\n", #c), 0) )
6 #define TESTR(r, f, m) ( \
7 ((r) = (f)) == 0 || (t_error("%s failed: %s (" m ")\n", #f, strerror(r)), 0) )
9 static pthread_key_t k1
, k2
;
11 static void dtor(void *p
)
16 static void *start(void *arg
)
19 if (pthread_setspecific(k1
, p
) || pthread_setspecific(k2
, p
+1))
31 /* Test POSIX thread-specific data */
32 TESTR(r
, pthread_key_create(&k1
, dtor
), "failed to create key");
33 TESTR(r
, pthread_key_create(&k2
, dtor
), "failed to create key");
35 TESTR(r
, pthread_setspecific(k1
, bar
), "failed to set tsd");
36 TESTR(r
, pthread_setspecific(k2
, bar
+1), "failed to set tsd");
37 TESTR(r
, pthread_create(&td
, 0, start
, foo
), "failed to create thread");
38 TESTR(r
, pthread_join(td
, &res
), "failed to join");
39 TESTC(res
== 0, "pthread_setspecific failed in thread");
40 TESTC(foo
[0] == 1, "dtor failed to run");
41 TESTC(foo
[1] == 1, "dtor failed to run");
42 TESTC(pthread_getspecific(k1
) == bar
, "tsd corrupted");
43 TESTC(pthread_getspecific(k2
) == bar
+1, "tsd corrupted");
44 TESTR(r
, pthread_setspecific(k1
, 0), "failed to clear tsd");
45 TESTR(r
, pthread_setspecific(k2
, 0), "failed to clear tsd");
46 TESTR(r
, pthread_key_delete(k1
), "failed to destroy key");
47 TESTR(r
, pthread_key_delete(k2
), "failed to destroy key");