test pthread_detach.

This commit is contained in:
yamt 2005-01-21 11:54:24 +00:00
parent d68085a6b6
commit cd4834a432
2 changed files with 70 additions and 0 deletions

View File

@ -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 <bsd.prog.mk>

View File

@ -0,0 +1,55 @@
/* $NetBSD: detach1.c,v 1.1 2005/01/21 11:54:24 yamt Exp $ */
#include <err.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#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);
}