From e0b68aae21da8697ef0f4f3924ea29edb0e89582 Mon Sep 17 00:00:00 2001
From: rpj <rpj>
Date: Thu, 29 Oct 1998 20:58:36 +0000
Subject: Fri Oct 30 15:15:50 1998  Ross Johnson  <rpj@swan.canberra.edu.au>   
      * cleanup.c (_pthread_handler_push): Fixed bug appending new        
 handler to list reported by Peter Slacik        
 <Peter.Slacik@leibinger.freinet.de>.         (new_thread): Rename poorly
 named local variable to         "new_handler".

---
 tests/ChangeLog |  4 ++++
 tests/tsd1.c    | 35 ++++++++++++++++++++++++++++++-----
 2 files changed, 34 insertions(+), 5 deletions(-)

(limited to 'tests')

diff --git a/tests/ChangeLog b/tests/ChangeLog
index 6217b28..a634f87 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,7 @@
+Fri Oct 16 17:59:49 1998  Ross Johnson  <rpj@swan.canberra.edu.au>
+
+	* tsd1.c (destroy_key): Add function. Change diagnostics.
+
 Thu Oct 15 17:42:37 1998  Ross Johnson  <rpj@swan.canberra.edu.au>
 
 	* tsd1.c (mythread): Fix some casts and add some message
diff --git a/tests/tsd1.c b/tests/tsd1.c
index 06ffab5..aa2d3da 100644
--- a/tests/tsd1.c
+++ b/tests/tsd1.c
@@ -4,10 +4,22 @@
 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
-- 
cgit v1.2.3