test pthread_detach.
This commit is contained in:
parent
d68085a6b6
commit
cd4834a432
15
regress/lib/libpthread/detach1/Makefile
Normal file
15
regress/lib/libpthread/detach1/Makefile
Normal 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>
|
55
regress/lib/libpthread/detach1/detach1.c
Normal file
55
regress/lib/libpthread/detach1/detach1.c
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user