From: Antti Kantee Date: Mon, 19 Jan 2015 16:14:00 +0000 (+0100) Subject: test pthread_specificdata X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=bcd9f5a0e1e0c8ba5dc702c02e442d1bf478071c;p=rumpuser-xen.git test pthread_specificdata --- diff --git a/tests/libstdtests/pthread_test.c b/tests/libstdtests/pthread_test.c index 81bf62b..c661f51 100644 --- a/tests/libstdtests/pthread_test.c +++ b/tests/libstdtests/pthread_test.c @@ -18,6 +18,8 @@ static pthread_cond_t cv, cv2; static int nthreads = 4; +static pthread_key_t thrnumkey; + static void threxit(void *arg) { @@ -29,6 +31,11 @@ threxit(void *arg) } pthread_mutex_unlock(&mtx); + if (pthread_getspecific(thrnumkey) != arg) { + printf("ERROR: specificdata fail"); + abort(); + } + printf("thread %p EXIT %d\n", arg, nthreads); } @@ -37,6 +44,7 @@ mythread(void *arg) { printf("thread %p\n", arg); + pthread_setspecific(thrnumkey, arg); pthread_mutex_lock(&mtx); printf("got lock %p\n", arg); @@ -57,6 +65,7 @@ waitthread(void *arg) { printf("thread %p\n", arg); + pthread_setspecific(thrnumkey, arg); pthread_mutex_lock(&mtx); while (!predicate) { printf("no good, need to wait %p\n", arg); @@ -75,6 +84,7 @@ wakeupthread(void *arg) { printf("thread %p\n", arg); + pthread_setspecific(thrnumkey, arg); pthread_mutex_lock(&mtx); predicate = 1; printf("rise and shine %p!\n", arg); @@ -92,6 +102,8 @@ test_pthread(void) struct timespec ts; pthread_t pt; + pthread_key_create(&thrnumkey, NULL); + pthread_mutex_init(&mtx, NULL); pthread_cond_init(&cv, NULL); pthread_cond_init(&cv2, NULL);