diff options
author | Philip Guenther <guenther@cvs.openbsd.org> | 2017-10-16 01:46:10 +0000 |
---|---|---|
committer | Philip Guenther <guenther@cvs.openbsd.org> | 2017-10-16 01:46:10 +0000 |
commit | 9a6da0942837ec488f83f60705b3e8cb35bf9932 (patch) | |
tree | 3668fbcff9a1ec495a7f668ec2137227f86dc469 /regress/lib | |
parent | ace498db8cae402662dcecb9796dd083ff9244ba (diff) |
Add regress test for cancellation of pthread_once()'s init_routine
From Scott Cheloha (scottcheloha (at) gmail.com)
Diffstat (limited to 'regress/lib')
-rw-r--r-- | regress/lib/libpthread/Makefile | 4 | ||||
-rw-r--r-- | regress/lib/libpthread/pthread_once/Makefile | 5 | ||||
-rw-r--r-- | regress/lib/libpthread/pthread_once/pthread_once.c | 48 |
3 files changed, 55 insertions, 2 deletions
diff --git a/regress/lib/libpthread/Makefile b/regress/lib/libpthread/Makefile index 87bbc06040d..51bda49cc98 100644 --- a/regress/lib/libpthread/Makefile +++ b/regress/lib/libpthread/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.48 2017/07/07 23:55:21 bluhm Exp $ +# $OpenBSD: Makefile,v 1.49 2017/10/16 01:46:09 guenther Exp $ # disabled because it requires a buggy behavior that uthread had: # dup2_race @@ -18,7 +18,7 @@ SUBDIR+= barrier blocked_shutdown \ group netdb pcap poll preemption preemption_float \ pthread_atfork pthread_cond_timedwait pthread_create \ pthread_join pthread_kill pthread_mutex \ - pthread_rwlock pthread_specific \ + pthread_once pthread_rwlock pthread_specific \ readdir restart \ select semaphore setjmp sigdeliver siginfo \ siginterrupt signal signals signodefer sigsuspend sigwait sleep \ diff --git a/regress/lib/libpthread/pthread_once/Makefile b/regress/lib/libpthread/pthread_once/Makefile new file mode 100644 index 00000000000..38588ee6b14 --- /dev/null +++ b/regress/lib/libpthread/pthread_once/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2017/10/16 01:46:09 guenther Exp $ + +PROG= pthread_once + +.include <bsd.regress.mk> diff --git a/regress/lib/libpthread/pthread_once/pthread_once.c b/regress/lib/libpthread/pthread_once/pthread_once.c new file mode 100644 index 00000000000..7a1d103f14e --- /dev/null +++ b/regress/lib/libpthread/pthread_once/pthread_once.c @@ -0,0 +1,48 @@ +/* $OpenBSD: pthread_once.c,v 1.1 2017/10/16 01:46:09 guenther Exp $ */ + +/* + * Scott Cheloha <scottcheloha@gmail.com>, 2017. Public Domain. + */ + +#include <pthread.h> +#include <unistd.h> + +#include "test.h" + +pthread_once_t once_control = PTHREAD_ONCE_INIT; +int done = 0; + +void +init_routine(void) +{ + static int first = 1; + + if (first) { + first = 0; + CHECKr(pthread_cancel(pthread_self())); + pthread_testcancel(); + } + done = 1; +} + +void * +thread_main(void *arg) +{ + pthread_once(&once_control, init_routine); + return NULL; +} + +int +main(int argc, char **argv) +{ + pthread_t tid; + + CHECKr(pthread_create(&tid, NULL, thread_main, NULL)); + CHECKr(pthread_join(tid, NULL)); + ASSERT(!done); + alarm(5); /* if this rings we are probably deadlocked */ + CHECKr(pthread_once(&once_control, init_routine)); + alarm(0); + ASSERT(done); + SUCCEED; +}
\ No newline at end of file |