From 7522a5a3b4f87f79534ae134a087d80e3e4bfa8a Mon Sep 17 00:00:00 2001 From: rpj Date: Sun, 11 Oct 1998 19:51:50 +0000 Subject: Mon Oct 12 02:12:29 1998 Ross Johnson * tsd1.c: New. Test TSD using 1 key and 2 threads. --- tests/ChangeLog | 5 ++++- tests/tsd1.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 tests/tsd1.c diff --git a/tests/ChangeLog b/tests/ChangeLog index 081218f..074d5c4 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,7 @@ +Mon Oct 12 02:12:29 1998 Ross Johnson + + * tsd1.c: New. Test TSD using 1 key and 2 threads. + 1998-09-13 Ben Elliston * eyal1.c: New file; contributed by Eyal Lebedinsky @@ -17,4 +21,3 @@ * exit2.c: New file; test pthread_exit() harder. * exit1.c: New file; test pthread_exit(). - diff --git a/tests/tsd1.c b/tests/tsd1.c new file mode 100644 index 0000000..cb105ae --- /dev/null +++ b/tests/tsd1.c @@ -0,0 +1,48 @@ +#include +#include + +pthread_key_t key; +pthread_once_t key_once = PTHREAD_ONCE_INIT; + +void +make_key(void) +{ + (void) pthread_key_create(&key, free); +} + +void * +mythread(void * arg) +{ + void *ptr; + + (void) pthread_once(&key_once, make_key); + if ((ptr = pthread_getspecific(key)) == NULL) + { + ptr = malloc(80); + sprintf(ptr, "Thread %d\n", (int) arg); + (void) pthread_setspecific(key, ptr); + } + + if (pthread_getspecific(key) == NULL) + printf((char *) pthread_getspecific(key)); + else + printf("Failed %d\n", (int) arg); + + return 0; +} + +int +main() +{ + int rc; + pthread_t t1, t2; + + rc = pthread_create(&t1, NULL, mythread, 1); + printf("pthread_create returned %d\n", rc); + + rc = pthread_create(&t2, NULL, mythread, 2); + printf("pthread_create returned %d\n", rc); + + Sleep(2000); + return 0; +} -- cgit v1.2.3