summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorivmai <ivmai>2011-05-11 09:41:49 +0200
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 19:06:59 +0200
commit75827f128a6843990f7fa778e6641b1f1ddeddca (patch)
tree7cb6656b4ca3d60ea323812e14f520a1dee08e41 /tests
parent88a952ac5dd3c0582a82a1f2acfa277f5eaf4047 (diff)
2011-05-11 Ivan Maidanski <ivmai@mail.ru> (mostly really Ludovic Courtes)
* tests/threadkey_test.c: New file. * .cvsignore (threadkey_test): Add. * tests/tests.am (TESTS, check_PROGRAMS): Add 'threadkey_test'. * tests/tests.am (threadkey_test_SOURCES, threadkey_test_LDADD): New variable. * Makefile.in: Regenerate.
Diffstat (limited to 'tests')
-rw-r--r--tests/tests.am5
-rw-r--r--tests/threadkey_test.c61
2 files changed, 66 insertions, 0 deletions
diff --git a/tests/tests.am b/tests/tests.am
index e773c45..2ef84ba 100644
--- a/tests/tests.am
+++ b/tests/tests.am
@@ -68,6 +68,11 @@ check_PROGRAMS += threadleaktest
threadleaktest_SOURCES = tests/thread_leak_test.c
threadleaktest_LDADD = $(test_ldadd)
+TESTS += threadkey_test$(EXEEXT)
+check_PROGRAMS += threadkey_test
+threadkey_test_SOURCES = tests/threadkey_test.c
+threadkey_test_LDADD = $(test_ldadd)
+
TESTS += initsecondarythread$(EXEEXT)
check_PROGRAMS += initsecondarythread
initsecondarythread_SOURCES = tests/initsecondarythread.c
diff --git a/tests/threadkey_test.c b/tests/threadkey_test.c
new file mode 100644
index 0000000..5b6a516
--- /dev/null
+++ b/tests/threadkey_test.c
@@ -0,0 +1,61 @@
+
+#ifndef GC_THREADS
+# define GC_THREADS
+#endif
+
+#define GC_NO_THREAD_REDIRECTS 1
+
+#include "gc.h"
+
+#include <pthread.h>
+
+pthread_key_t key;
+pthread_once_t key_once = PTHREAD_ONCE_INIT;
+
+void * entry (void *arg)
+{
+ pthread_setspecific(key,
+ (void *)GC_HIDE_POINTER(GC_STRDUP("hello, world")));
+ return arg;
+}
+
+void * GC_CALLBACK on_thread_exit_inner (struct GC_stack_base * sb, void * arg)
+{
+ int res = GC_register_my_thread (sb);
+ pthread_t t;
+
+ GC_pthread_create (&t, NULL, entry, NULL);
+ if (res == GC_SUCCESS)
+ GC_unregister_my_thread ();
+ return NULL;
+}
+
+void on_thread_exit (void *v)
+{
+ GC_call_with_stack_base (on_thread_exit_inner, NULL);
+}
+
+void make_key (void)
+{
+ pthread_key_create (&key, on_thread_exit);
+}
+
+#ifndef LIMIT
+# define LIMIT 50
+#endif
+
+int main (void)
+{
+ int i;
+ GC_INIT ();
+
+ pthread_once (&key_once, make_key);
+
+ for (i = 0; i < LIMIT; i++)
+ {
+ pthread_t t;
+ GC_pthread_create (&t, NULL, entry, NULL);
+ }
+
+ return 0;
+}