From 2ef097640758653a0e9d63e90a4aac329cd86368 Mon Sep 17 00:00:00 2001 From: rpj Date: Mon, 22 Feb 1999 02:54:12 +0000 Subject: 1999-02-23 Ross Johnson * Makefile: Some refinement. * *.c: More exhaustive checking through assertions; clean up; add some more tests. --- tests/once1.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'tests/once1.c') diff --git a/tests/once1.c b/tests/once1.c index 661d322..91dc038 100644 --- a/tests/once1.c +++ b/tests/once1.c @@ -1,25 +1,29 @@ /* - * Test for pthread_once(). + * once1.c * - * Depends on functions: pthread_create. + * Create a static pthread_once and test that it calls myfunc once. + * + * Depends on API functions: + * pthread_once() + * pthread_create() */ -#include -#include +#include "test.h" pthread_once_t once = PTHREAD_ONCE_INIT; +static int washere = 0; + void myfunc(void) { - printf("only see this once\n"); + washere++; } void * mythread(void * arg) { - int rc = pthread_once(&once, myfunc); - printf("returned %d\n", rc); + assert(pthread_once(&once, myfunc) == 0); return 0; } @@ -27,19 +31,15 @@ mythread(void * arg) int main() { - int rc; pthread_t t1, t2; - if (pthread_create(&t1, NULL, mythread, NULL) != 0) - { - return 1; - } + assert(pthread_create(&t1, NULL, mythread, NULL) == 0); - if (pthread_create(&t2, NULL, mythread, NULL) != 0) - { - return 1; - } + assert(pthread_create(&t2, NULL, mythread, NULL) == 0); Sleep(2000); + + assert(washere == 1); + return 0; } -- cgit v1.2.3