From cd4834a4322ade41734a9e08abe985cfb7ca3842 Mon Sep 17 00:00:00 2001 From: yamt Date: Fri, 21 Jan 2005 11:54:24 +0000 Subject: [PATCH] test pthread_detach. --- regress/lib/libpthread/detach1/Makefile | 15 +++++++ regress/lib/libpthread/detach1/detach1.c | 55 ++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 regress/lib/libpthread/detach1/Makefile create mode 100644 regress/lib/libpthread/detach1/detach1.c diff --git a/regress/lib/libpthread/detach1/Makefile b/regress/lib/libpthread/detach1/Makefile new file mode 100644 index 000000000000..665b3485057a --- /dev/null +++ b/regress/lib/libpthread/detach1/Makefile @@ -0,0 +1,15 @@ +# $NetBSD: Makefile,v 1.1 2005/01/21 11:54:24 yamt Exp $ + +WARNS=3 + +PROG= detach1 + +LDADD= -lpthread +CPPFLAGS+= -I/usr/src/lib/libpthread/arch/i386 + +NOMAN= + +regress: + ./${PROG} + +.include diff --git a/regress/lib/libpthread/detach1/detach1.c b/regress/lib/libpthread/detach1/detach1.c new file mode 100644 index 000000000000..25435693ac01 --- /dev/null +++ b/regress/lib/libpthread/detach1/detach1.c @@ -0,0 +1,55 @@ +/* $NetBSD: detach1.c,v 1.1 2005/01/21 11:54:24 yamt Exp $ */ + +#include +#include +#include +#include +#include +#include + +#define NITER 100000 + +void *func(void *); +int main(void); + +void * +func(void *dummy) +{ + + return NULL; +} + +int +main() +{ + int i; + + for (i = 0; i < NITER; i++) { + pthread_t t; + int error; + + if (pthread_create(&t, NULL, func, NULL)) { + /* + * sleep and retry once for the case that + * the child threads are not finished yet. + */ + printf("%d sleeping...\n", i); + sleep(10); + if (pthread_create(&t, NULL, func, NULL)) + err(1, "create"); + } + + if (i & 1) + sched_yield(); /* give a chance thread to finish */ + if (pthread_detach(t)) + err(1, "detach"); + + error = pthread_join(t, NULL); + if (error != ESRCH && error != EINVAL) { + printf("unexpected error %d\n", error); + exit(3); + } + } + + exit(0); +}