diff --git a/regress/lib/libpthread/Makefile b/regress/lib/libpthread/Makefile index 4b9b4ca6ae11..fe48d90b9bb2 100644 --- a/regress/lib/libpthread/Makefile +++ b/regress/lib/libpthread/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.19 2004/05/21 16:08:47 christos Exp $ +# $NetBSD: Makefile,v 1.20 2004/07/07 21:53:10 nathanw Exp $ .include @@ -16,7 +16,7 @@ ARCHSUBDIR= ${MACHINE_CPU} .if defined(ARCHSUBDIR) SUBDIR+= atexit barrier1 cancel2 cond1 cond2 cond3 cond4 cond5 condcancel1 \ - exit1 fork mutex1 mutex2 mutex3 mutex4 name once1 once2 \ + conddestroy1 exit1 fork mutex1 mutex2 mutex3 mutex4 name once1 once2 \ preempt1 resolv sem sigalarm sigmask1 siglongjmp1 sigsuspend .endif diff --git a/regress/lib/libpthread/conddestroy1/Makefile b/regress/lib/libpthread/conddestroy1/Makefile new file mode 100644 index 000000000000..cdfbbd3e88de --- /dev/null +++ b/regress/lib/libpthread/conddestroy1/Makefile @@ -0,0 +1,15 @@ +# $NetBSD: Makefile,v 1.1 2004/07/07 21:53:10 nathanw Exp $ + +WARNS=1 + +PROG= conddestroy1 +SRCS= conddestroy1.c + +LDADD= -lpthread + +NOMAN= + +regress: + ./conddestroy1 + +.include diff --git a/regress/lib/libpthread/conddestroy1/conddestroy1.c b/regress/lib/libpthread/conddestroy1/conddestroy1.c new file mode 100644 index 000000000000..c6d65117c9cb --- /dev/null +++ b/regress/lib/libpthread/conddestroy1/conddestroy1.c @@ -0,0 +1,77 @@ +/* $NetBSD: conddestroy1.c,v 1.1 2004/07/07 21:53:10 nathanw Exp $ */ + +#include +#include +#include +#include + +void handler(int); +void *threadroutine(void *); + +pthread_mutex_t mt; +pthread_cond_t cv; + +void +handler(int sig) +{ + /* Dummy */ + return; +} + +void * +threadroutine(void *arg) +{ + sigset_t set; + + sigemptyset(&set); + sigaddset(&set, SIGALRM); + + pthread_sigmask(SIG_UNBLOCK, &set, NULL); + + pthread_mutex_lock(&mt); + + /* + * Explicitly not a loop; we want to see if the cv is properly + * torn down in a spurious wakeup (generated here by SIGALRM). + */ + pthread_cond_wait(&cv, &mt); + + pthread_mutex_unlock(&mt); + + return NULL; +} + +int +main(void) +{ + pthread_t th; + sigset_t set; + struct sigaction act; + + printf("Testing CV teardown under spurious wakeups.\n"); + + sigfillset(&set); + + pthread_sigmask(SIG_BLOCK, &set, NULL); + + act.sa_handler = handler; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + + sigaction(SIGALRM, &act, NULL); + + pthread_mutex_init(&mt, NULL); + pthread_cond_init(&cv, NULL); + + pthread_create(&th, NULL, threadroutine, NULL); + + alarm(1); + + pthread_join(th, NULL); + + pthread_cond_destroy(&cv); + pthread_mutex_destroy(&mt); + + printf("Passed.\n"); + return 0; +}