summaryrefslogtreecommitdiff
path: root/regress/lib/libpthread/cancel2/cancel2.c
blob: 275ad8d8b61bc61566fd8a5a1fd9e1517b19cdf3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* $OpenBSD: cancel2.c,v 1.1 2003/01/19 21:23:46 marc Exp $ */
/* PUBLIC DOMAIN <marc@snafu.org> */

/*
 * Check that a thread waiting on a select without timeout can be
 * cancelled.
 */

#include <sys/types.h>
#include <sys/time.h>

#include <pthread.h>
#include <unistd.h>

#include "test.h"

void *
select_thread(void *arg)
{
	int read_fd = *(int*) arg;
	fd_set read_fds;
	int result;

	FD_ZERO(&read_fds);
	FD_SET(read_fd, &read_fds);
	result = select(read_fd + 1, &read_fds, NULL, NULL, NULL);
	printf("select returned %d\n", result);
	return 0;
}

int
main(int argc, char *argv[])
{
	pthread_t thread;
	int pipe_fd[2];

	CHECKe(pipe(pipe_fd));
	CHECKr(pthread_create(&thread, NULL, select_thread, pipe_fd));
	sleep(2);
	CHECKr(pthread_cancel(thread));
	CHECKr(pthread_join(thread, NULL));
	SUCCEED;
}