]> git.saurik.com Git - apple/libpthread.git/blame - tests/tsd.c
libpthread-416.40.3.tar.gz
[apple/libpthread.git] / tests / tsd.c
CommitLineData
964d3577
A
1#include <pthread.h>
2#include <stdio.h>
3
a0619f9c 4#include "darwintest_defaults.h"
964d3577 5
2546420a
A
6static void *ptr = NULL;
7
8static void destructor(void *value)
964d3577
A
9{
10 ptr = value;
11}
12
2546420a 13static void *thread(void *param)
964d3577 14{
964d3577 15 pthread_key_t key = *(pthread_key_t *)param;
2546420a 16 T_ASSERT_POSIX_ZERO(pthread_setspecific(key, (void *)0x12345678), NULL);
964d3577
A
17 void *value = pthread_getspecific(key);
18
2546420a
A
19 T_ASSERT_POSIX_ZERO(pthread_key_create(&key, NULL), NULL);
20 T_ASSERT_POSIX_ZERO(pthread_setspecific(key, (void *)0x55555555), NULL);
964d3577
A
21
22 return value;
23}
24
2546420a 25T_DECL(tsd, "tsd",
a0619f9c 26 T_META_ALL_VALID_ARCHS(YES))
964d3577 27{
964d3577
A
28 pthread_key_t key;
29
2546420a
A
30 T_ASSERT_POSIX_ZERO(pthread_key_create(&key, destructor), NULL);
31 T_LOG("key = %ld", key);
964d3577
A
32
33 pthread_t p = NULL;
2546420a 34 T_ASSERT_POSIX_ZERO(pthread_create(&p, NULL, thread, &key), NULL);
964d3577
A
35
36 void *value = NULL;
2546420a
A
37 T_ASSERT_POSIX_ZERO(pthread_join(p, &value), NULL);
38 T_LOG("value = %p; ptr = %p\n", value, ptr);
964d3577 39
2546420a 40 T_EXPECT_EQ(ptr, value, NULL);
964d3577 41
2546420a 42 T_ASSERT_POSIX_ZERO(pthread_key_delete(key), NULL);
964d3577 43}