summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpj <rpj>1998-10-15 00:46:01 +0000
committerrpj <rpj>1998-10-15 00:46:01 +0000
commit2a58055edb81dbc4b22601c0678c34209e3b0718 (patch)
treefbb0da29185a762055d106828ee22e4a0d0ef0c5
parent89a4d0ca16686de0a331b6ad85f3fec9b8fec679 (diff)
Thu Oct 15 17:42:37 1998 Ross Johnson <rpj@swan.canberra.edu.au>
* tsd1.c (mythread): Fix some casts and add some diagnostics. Fix inverted conditional.
-rw-r--r--tests/ChangeLog5
-rw-r--r--tests/tsd1.c32
2 files changed, 28 insertions, 9 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 074d5c4..6217b28 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+Thu Oct 15 17:42:37 1998 Ross Johnson <rpj@swan.canberra.edu.au>
+
+ * tsd1.c (mythread): Fix some casts and add some message
+ output. Fix inverted conditional.
+
Mon Oct 12 02:12:29 1998 Ross Johnson <rpj@ixobrychus.canberra.edu.au>
* tsd1.c: New. Test TSD using 1 key and 2 threads.
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);