]>
Commit | Line | Data |
---|---|---|
1 | #include <pthread.h> | |
2 | #include <stdio.h> | |
3 | ||
4 | #include "darwintest_defaults.h" | |
5 | ||
6 | static void *ptr = NULL; | |
7 | ||
8 | static void destructor(void *value) | |
9 | { | |
10 | ptr = value; | |
11 | } | |
12 | ||
13 | static void *thread(void *param) | |
14 | { | |
15 | pthread_key_t key = *(pthread_key_t *)param; | |
16 | T_ASSERT_POSIX_ZERO(pthread_setspecific(key, (void *)0x12345678), NULL); | |
17 | void *value = pthread_getspecific(key); | |
18 | ||
19 | T_ASSERT_POSIX_ZERO(pthread_key_create(&key, NULL), NULL); | |
20 | T_ASSERT_POSIX_ZERO(pthread_setspecific(key, (void *)0x55555555), NULL); | |
21 | ||
22 | return value; | |
23 | } | |
24 | ||
25 | T_DECL(tsd, "tsd", | |
26 | T_META_ALL_VALID_ARCHS(YES)) | |
27 | { | |
28 | pthread_key_t key; | |
29 | ||
30 | T_ASSERT_POSIX_ZERO(pthread_key_create(&key, destructor), NULL); | |
31 | T_LOG("key = %ld", key); | |
32 | ||
33 | pthread_t p = NULL; | |
34 | T_ASSERT_POSIX_ZERO(pthread_create(&p, NULL, thread, &key), NULL); | |
35 | ||
36 | void *value = NULL; | |
37 | T_ASSERT_POSIX_ZERO(pthread_join(p, &value), NULL); | |
38 | T_LOG("value = %p; ptr = %p\n", value, ptr); | |
39 | ||
40 | T_EXPECT_EQ(ptr, value, NULL); | |
41 | ||
42 | T_ASSERT_POSIX_ZERO(pthread_key_delete(key), NULL); | |
43 | } |