diff options
author | Thomas Schwinge <thomas@codesourcery.com> | 2012-08-30 23:29:21 +0200 |
---|---|---|
committer | Thomas Schwinge <thomas@codesourcery.com> | 2012-08-30 23:29:21 +0200 |
commit | 6b1ebd29a16f2c2c91f8fcae4ce2b5dd62143821 (patch) | |
tree | 026e82163d438015f9fe828e16a174ee1a405803 /tests/test-17.c | |
parent | 13aeb1df3614cbb0c0dc074427ab2f95160af0bb (diff) | |
parent | 0096579c8bea920f7c42b40ea22db621da6480a5 (diff) |
Merge commit 'refs/top-bases/t/fix_have_kernel_resources' into t/fix_have_kernel_resourcest/fix_have_kernel_resources
Diffstat (limited to 'tests/test-17.c')
-rw-r--r-- | tests/test-17.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/test-17.c b/tests/test-17.c new file mode 100644 index 0000000..a8bd150 --- /dev/null +++ b/tests/test-17.c @@ -0,0 +1,57 @@ +/* Test that the key reuse inside libpthread does not cause thread + specific values to persist. */ + +#define _GNU_SOURCE 1 + +#include <pthread.h> +#include <stdio.h> +#include <assert.h> +#include <errno.h> + +void +work (int iter) +{ + error_t err; + pthread_key_t key1; + pthread_key_t key2; + void *value1; + void *value2; + + printf ("work/%d: start\n", iter); + err = pthread_key_create (&key1, NULL); + assert (err == 0); + err = pthread_key_create (&key2, NULL); + assert (err == 0); + + value1 = pthread_getspecific (key1); + value2 = pthread_getspecific (key2); + printf ("work/%d: pre-setspecific: %p,%p\n", iter, value1, value2); + assert (value1 == NULL); + assert (value2 == NULL); + err = pthread_setspecific (key1, (void *)(0x100 + iter)); + assert (err == 0); + err = pthread_setspecific (key2, (void *)(0x200 + iter)); + assert (err == 0); + + value1 = pthread_getspecific (key1); + value2 = pthread_getspecific (key2); + printf ("work/%d: post-setspecific: %p,%p\n", iter, value1, value2); + assert (value1 == (void *)(0x100 + iter)); + assert (value2 == (void *)(0x200 + iter)); + + err = pthread_key_delete (key1); + assert (err == 0); + err = pthread_key_delete (key2); + assert (err == 0); +} + +int +main (int argc, char *argv[]) +{ + int i; + + for (i = 0; i < 8; ++i) + work (i + 1); + + return 0; +} |