diff options
author | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2012-02-27 23:40:38 +0000 |
---|---|---|
committer | Federico G. Schwindt <fgsch@cvs.openbsd.org> | 2012-02-27 23:40:38 +0000 |
commit | 0078f3261d35531643989ca51d263fb4aeb61dda (patch) | |
tree | 8a76238c9b9678fe84a4ddadf3287b9d3dfb4b1a /regress | |
parent | 8713f1cc84785e65e7395b05eb9e6b1870df88da (diff) |
test based on python's dubious test_3_join_in_forked_from_thread test.
Diffstat (limited to 'regress')
-rw-r--r-- | regress/lib/libpthread/blocked_join/Makefile | 5 | ||||
-rw-r--r-- | regress/lib/libpthread/blocked_join/blocked_join.c | 54 |
2 files changed, 59 insertions, 0 deletions
diff --git a/regress/lib/libpthread/blocked_join/Makefile b/regress/lib/libpthread/blocked_join/Makefile new file mode 100644 index 00000000000..0ff3f04b83d --- /dev/null +++ b/regress/lib/libpthread/blocked_join/Makefile @@ -0,0 +1,5 @@ +# $OpenBSD: Makefile,v 1.1 2012/02/27 23:40:37 fgsch Exp $ + +PROG = blocked_join + +.include <bsd.regress.mk> diff --git a/regress/lib/libpthread/blocked_join/blocked_join.c b/regress/lib/libpthread/blocked_join/blocked_join.c new file mode 100644 index 00000000000..0032dfbd184 --- /dev/null +++ b/regress/lib/libpthread/blocked_join/blocked_join.c @@ -0,0 +1,54 @@ +/* $OpenBSD: blocked_join.c,v 1.1 2012/02/27 23:40:37 fgsch Exp $ */ +/* + * Federico G. Schwindt <fgsch@openbsd.org>, 2012. Public Domain. + */ + +#include <sys/types.h> +#include <sys/wait.h> +#include <pthread.h> +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include "test.h" + +void * +deadlock_detector(void *arg) +{ + sleep(10); + PANIC("deadlock detected"); +} + +void * +joiner(void *arg) +{ + pthread_t mainthread = *(pthread_t *)arg; + ASSERT(pthread_join(mainthread, NULL) == EDEADLK); + return (NULL); +} + +int +main(int argc, char **argv) +{ + pthread_t d, t, self = pthread_self(); + pid_t pid; + + switch ((pid = fork())) { + case -1: + PANIC("cannot fork"); + /* NOTREACHED */ + + case 0: + /* child */ + break; + + default: + CHECKr(waitpid(pid, NULL, 0)); + _exit(0); + /* NOTREACHED */ + } + + CHECKr(pthread_create(&d, NULL, deadlock_detector, NULL)); + CHECKr(pthread_create(&t, NULL, joiner, &self)); + CHECKr(pthread_join(t, NULL)); + SUCCEED; +} |