xref: /openbsd-src/regress/lib/libpthread/cancel2/cancel2.c (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /* $OpenBSD: cancel2.c,v 1.2 2003/07/31 21:48:04 deraadt Exp $ */
2 /* PUBLIC DOMAIN <marc@snafu.org> */
3 
4 /*
5  * Check that a thread waiting on a select without timeout can be
6  * cancelled.
7  */
8 
9 #include <sys/types.h>
10 #include <sys/time.h>
11 
12 #include <pthread.h>
13 #include <unistd.h>
14 
15 #include "test.h"
16 
17 static void *
18 select_thread(void *arg)
19 {
20 	int read_fd = *(int*) arg;
21 	fd_set read_fds;
22 	int result;
23 
24 	FD_ZERO(&read_fds);
25 	FD_SET(read_fd, &read_fds);
26 	result = select(read_fd + 1, &read_fds, NULL, NULL, NULL);
27 	printf("select returned %d\n", result);
28 	return 0;
29 }
30 
31 int
32 main(int argc, char *argv[])
33 {
34 	pthread_t thread;
35 	int pipe_fd[2];
36 
37 	CHECKe(pipe(pipe_fd));
38 	CHECKr(pthread_create(&thread, NULL, select_thread, pipe_fd));
39 	sleep(2);
40 	CHECKr(pthread_cancel(thread));
41 	CHECKr(pthread_join(thread, NULL));
42 	SUCCEED;
43 }
44