3 # include "private/config.h"
10 #define GC_NO_THREAD_REDIRECTS 1
14 #if (!defined(GC_PTHREADS) || defined(GC_SOLARIS_THREADS) \
15 || defined(__native_client__)) && !defined(SKIP_THREADKEY_TEST)
16 /* FIXME: Skip this test on Solaris for now. The test may fail on */
17 /* other targets as well. Currently, tested only on Linux, Cygwin */
19 # define SKIP_THREADKEY_TEST
22 #ifdef SKIP_THREADKEY_TEST
28 printf("threadkey_test skipped\n");
38 #ifdef GC_SOLARIS_THREADS
39 /* pthread_once_t key_once = { PTHREAD_ONCE_INIT }; */
41 pthread_once_t key_once = PTHREAD_ONCE_INIT;
44 void * entry (void *arg)
46 pthread_setspecific(key,
47 (void *)GC_HIDE_POINTER(GC_STRDUP("hello, world")));
51 void * GC_CALLBACK on_thread_exit_inner (struct GC_stack_base * sb, void * arg)
53 int res = GC_register_my_thread (sb);
55 int creation_res; /* Used to suppress a warning about */
56 /* unchecked pthread_create() result. */
58 creation_res = GC_pthread_create (&t, NULL, entry, NULL);
59 if (res == GC_SUCCESS)
60 GC_unregister_my_thread ();
62 return (void*)(GC_word)creation_res;
65 void on_thread_exit (void *v)
67 GC_call_with_stack_base (on_thread_exit_inner, NULL);
72 pthread_key_create (&key, on_thread_exit);
84 # ifdef GC_SOLARIS_THREADS
85 pthread_key_create (&key, on_thread_exit);
87 pthread_once (&key_once, make_key);
89 for (i = 0; i < LIMIT; i++) {
92 if (GC_pthread_create (&t, NULL, entry, NULL) == 0
94 GC_pthread_join (t, &res);
99 #endif /* !SKIP_THREADKEY_TEST */