1/* $OpenBSD: pthread_join.c,v 1.1 2011/10/01 10:26:59 fgsch Exp $ */ 2/* 3 * Federico G. Schwindt <fgsch@openbsd.org>, 2011. Public Domain. 4 */ 5#include <pthread.h> 6#include <signal.h> 7#include <unistd.h> 8#include "test.h" 9 10volatile sig_atomic_t hits = 0; 11 12void 13handler(int sig) 14{ 15 hits++; 16} 17 18void * 19thr_sleep(void *arg) 20{ 21 return ((caddr_t)NULL + sleep(5)); 22} 23 24void * 25thr_join(void *arg) 26{ 27 pthread_t tid = *(pthread_t *)arg; 28 void *retval; 29 30 CHECKr(pthread_join(tid, &retval)); 31 return (retval); 32} 33 34int 35main(int argc, char **argv) 36{ 37 struct sigaction sa; 38 pthread_t tid[2]; 39 void *retval; 40 41 bzero(&sa, sizeof(sa)); 42 sa.sa_handler = handler; 43 CHECKe(sigaction(SIGUSR1, &sa, NULL)); 44 45 CHECKr(pthread_create(&tid[0], NULL, thr_sleep, NULL)); 46 CHECKr(pthread_create(&tid[1], NULL, thr_join, &tid[0])); 47 sleep(2); 48 49 CHECKr(pthread_kill(tid[1], SIGUSR1)); 50 sleep(2); 51 52 ASSERT(hits == 1); 53 CHECKr(pthread_join(tid[1], &retval)); 54 ASSERT(retval == (void *)0); 55 SUCCEED; 56} 57