summaryrefslogtreecommitdiff
path: root/tests/tsd1.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tsd1.c')
-rw-r--r--tests/tsd1.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/tests/tsd1.c b/tests/tsd1.c
index 06ffab5..aa2d3da 100644
--- a/tests/tsd1.c
+++ b/tests/tsd1.c
@@ -5,9 +5,21 @@ pthread_key_t key;
pthread_once_t key_once = PTHREAD_ONCE_INIT;
void
+destroy_key(void * arg)
+{
+ /* arg is not NULL if we get to here. */
+ printf("SUCCESS: %s: destroying key.\n", (char *) arg);
+
+ free((char *) arg);
+
+ /* Is it our responsibility to do this? */
+ arg = NULL;
+}
+
+void
make_key(void)
{
- if (pthread_key_create(&key, free) != 0)
+ if (pthread_key_create(&key, destroy_key) != 0)
{
printf("Key create failed\n");
exit(1);
@@ -31,18 +43,31 @@ mythread(void * arg)
else
{
ptr = (void *) malloc(80);
- sprintf((char *) ptr, "Thread %d Key 0x%x succeeded\n",
+ sprintf((char *) ptr, "Thread %d Key 0x%x",
(int) arg,
(int) key);
(void) pthread_setspecific(key, ptr);
}
- if ((ptr = pthread_getspecific(key)) != NULL)
- printf((char *) ptr);
+ if ((ptr = pthread_getspecific(key)) == NULL)
+ {
+ printf("FAILED: Thread %d Key 0x%x: key value set or get failed.\n",
+ (int) arg,
+ (int) key);
+ exit(1);
+ }
else
- printf("Failed %d\n", (int) arg);
+ {
+ printf("SUCCESS: Thread %d Key 0x%x: key value set and get succeeded.\n",
+ (int) arg,
+ (int) key);
+
+ printf("SUCCESS: %s: exiting thread.\n", (char *) ptr);
+ }
return 0;
+
+ /* Exiting the thread will call the key destructor. */
}
int