summaryrefslogtreecommitdiff
path: root/open_issues
diff options
context:
space:
mode:
Diffstat (limited to 'open_issues')
-rw-r--r--open_issues/libpthread_pthread_key_create_reuse.mdwn2
-rw-r--r--open_issues/libpthread_pthread_key_create_reuse/pthread_key_create_reuse.c48
2 files changed, 50 insertions, 0 deletions
diff --git a/open_issues/libpthread_pthread_key_create_reuse.mdwn b/open_issues/libpthread_pthread_key_create_reuse.mdwn
index 11c9a821..a5704d0f 100644
--- a/open_issues/libpthread_pthread_key_create_reuse.mdwn
+++ b/open_issues/libpthread_pthread_key_create_reuse.mdwn
@@ -45,3 +45,5 @@ IRC, FreeNode, #hurd, 2011-07-02
< youpi> that's the pity part
< pinotree> youpi: the licq case could look like a similar issue, at a
veeery quick glance
+
+Test program: [[pthread_key_create_reuse.c]]
diff --git a/open_issues/libpthread_pthread_key_create_reuse/pthread_key_create_reuse.c b/open_issues/libpthread_pthread_key_create_reuse/pthread_key_create_reuse.c
new file mode 100644
index 00000000..f7f5874e
--- /dev/null
+++ b/open_issues/libpthread_pthread_key_create_reuse/pthread_key_create_reuse.c
@@ -0,0 +1,48 @@
+#include <pthread.h>
+#include <stdio.h>
+#include <assert.h>
+
+#define DEBUG
+
+void del(void *x __attribute__((unused)))
+{
+}
+
+void work(int val)
+{
+ pthread_key_t key1;
+ pthread_key_t key2;
+
+#ifdef DEBUG
+ printf("work/%d: start\n", val);
+#endif
+ assert(pthread_key_create(&key1, &del) == 0);
+ assert(pthread_key_create(&key2, &del) == 0);
+#ifdef DEBUG
+ printf("work/%d: pre-setspecific: %p,%p\n", val, pthread_getspecific(key1), pthread_getspecific(key2));
+#else
+ assert(pthread_getspecific(key1) == NULL);
+ assert(pthread_getspecific(key2) == NULL);
+#endif
+ assert(pthread_setspecific(key1, (void *)(0x100 + val)) == 0);
+ assert(pthread_setspecific(key2, (void *)(0x200 + val)) == 0);
+#ifdef DEBUG
+ printf("work/%d: post-setspecific: %p,%p\n", val, pthread_getspecific(key1), pthread_getspecific(key2));
+#else
+ assert(pthread_getspecific(key1) == (void *)(0x100 + val));
+ assert(pthread_getspecific(key2) == (void *)(0x200 + val));
+#endif
+ assert(pthread_key_delete(key1) == 0);
+ assert(pthread_key_delete(key2) == 0);
+}
+
+int main()
+{
+ int i;
+
+ for (i = 0; i < 8; ++i) {
+ work(i + 1);
+ }
+
+ return 0;
+}