1 /*
2 * Copyright 2013 The Emscripten Authors. All rights reserved.
3 * Emscripten is available under two separate licenses, the MIT license and the
4 * University of Illinois/NCSA Open Source License. Both these licenses can be
5 * found in the LICENSE file.
6 */
7
8 #include <stdio.h>
9 #include <assert.h>
10 #include <errno.h>
11 #include <pthread.h>
12
destr_function(void * arg)13 static void destr_function(void *arg)
14 {
15 // Not implemented yet in Emscripten
16 }
17
main(void)18 int main(void)
19 {
20 pthread_key_t key = 0;
21 int rv;
22 int data = 123;
23 int *data2;
24
25 assert(pthread_key_delete(key) != 0);
26 assert(pthread_getspecific(key) == NULL);
27
28 rv = pthread_key_create(&key, &destr_function);
29 printf("pthread_key_create = %d\n", rv);
30 assert(rv == 0);
31
32 assert(pthread_getspecific(key) == NULL);
33
34 rv = pthread_setspecific(key, (void*) &data);
35 printf("pthread_setspecific = %d\n", rv);
36 assert(rv == 0);
37
38 data2 = pthread_getspecific(key);
39 assert(data2 != NULL);
40 printf("pthread_getspecific = %d\n", *data2);
41 assert(*data2 == 123);
42
43 rv = pthread_setspecific(key, NULL);
44 printf("valid pthread_setspecific for value NULL = %d\n", rv);
45 assert(rv == 0);
46
47 data2 = pthread_getspecific(key);
48 assert(data2 == NULL);
49 printf("pthread_getspecific = %p\n", data2);
50
51 rv = pthread_key_create(&key, &destr_function);
52 data2 = pthread_getspecific(key);
53 printf("pthread_getspecific after key recreate = %p\n", data2);
54 assert(data2 == NULL);
55
56 rv = pthread_key_delete(key);
57 printf("pthread_key_delete = %d\n", rv);
58 assert(rv == 0);
59
60 rv = pthread_key_delete(key);
61 printf("pthread_key_delete repeated = %d\n", rv);
62 assert(rv == EINVAL);
63
64 rv = pthread_setspecific(key, NULL);
65 printf("pthread_setspecific for value NULL = %d\n", rv);
66 assert(rv == EINVAL);
67
68 rv = pthread_key_create(&key, &destr_function);
69 assert(rv == 0);
70 rv = pthread_key_delete(key);
71 printf("pthread_key_delete just after created = %d\n", rv);
72 assert(rv == 0);
73
74 return 0;
75 }
76