From 2a58055edb81dbc4b22601c0678c34209e3b0718 Mon Sep 17 00:00:00 2001 From: rpj Date: Thu, 15 Oct 1998 00:46:01 +0000 Subject: Thu Oct 15 17:42:37 1998 Ross Johnson * tsd1.c (mythread): Fix some casts and add some diagnostics. Fix inverted conditional. --- tests/tsd1.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'tests/tsd1.c') diff --git a/tests/tsd1.c b/tests/tsd1.c index cb105ae..06ffab5 100644 --- a/tests/tsd1.c +++ b/tests/tsd1.c @@ -7,24 +7,38 @@ pthread_once_t key_once = PTHREAD_ONCE_INIT; void make_key(void) { - (void) pthread_key_create(&key, free); + if (pthread_key_create(&key, free) != 0) + { + printf("Key create failed\n"); + exit(1); + } } void * mythread(void * arg) { - void *ptr; + void * ptr; (void) pthread_once(&key_once, make_key); - if ((ptr = pthread_getspecific(key)) == NULL) + + if ((ptr = pthread_getspecific(key)) != NULL) + { + printf("ERROR: Thread %d, Key 0x%x not initialised to NULL\n", + (int) arg, + (int) key); + exit(1); + } + else { - ptr = malloc(80); - sprintf(ptr, "Thread %d\n", (int) arg); + ptr = (void *) malloc(80); + sprintf((char *) ptr, "Thread %d Key 0x%x succeeded\n", + (int) arg, + (int) key); (void) pthread_setspecific(key, ptr); } - if (pthread_getspecific(key) == NULL) - printf((char *) pthread_getspecific(key)); + if ((ptr = pthread_getspecific(key)) != NULL) + printf((char *) ptr); else printf("Failed %d\n", (int) arg); @@ -37,10 +51,10 @@ main() int rc; pthread_t t1, t2; - rc = pthread_create(&t1, NULL, mythread, 1); + rc = pthread_create(&t1, NULL, mythread, (void *) 1); printf("pthread_create returned %d\n", rc); - rc = pthread_create(&t2, NULL, mythread, 2); + rc = pthread_create(&t2, NULL, mythread, (void *) 2); printf("pthread_create returned %d\n", rc); Sleep(2000); -- cgit v1.2.3