summaryrefslogtreecommitdiff
path: root/tests/once1.c
diff options
context:
space:
mode:
authorrpj <rpj>1999-02-22 02:54:12 +0000
committerrpj <rpj>1999-02-22 02:54:12 +0000
commit2ef097640758653a0e9d63e90a4aac329cd86368 (patch)
tree71751f699b0aedba3227446ac228d30f2a127173 /tests/once1.c
parent943bc9bb02212649a83ec32152299d50d34226e6 (diff)
1999-02-23 Ross Johnson <rpj@ise.canberra.edu.au>
* Makefile: Some refinement. * *.c: More exhaustive checking through assertions; clean up; add some more tests.
Diffstat (limited to 'tests/once1.c')
-rw-r--r--tests/once1.c32
1 files changed, 16 insertions, 16 deletions
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 <pthread.h>
-#include <stdio.h>
+#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;
}