Trying again: select() should be a cancellation point

Daniel Eischen deischen at
Sat Jan 29 10:23:49 PST 2005

On Sat, 29 Jan 2005, Niall Douglas wrote:

> As no one replied last time, here's this email again.
> I've found that I cannot work around select() not being a
> cancellation point on FreeBSD in my code - I had to #ifdef
> __FreeBSD__ in a hack which manually calls pthread_testcancel() every
> second. This is *nasty*!
> If there's any alternative, I'd very much like to hear it. Preferably
> I'd like to see select() made a cancellation point or a new form of
> select() eg; select_tc() added.

select() is a cancellation point.  You're going to have to show
us that it isn't ;-)

#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

static volatile int done = 0;

static void
cleanup(void *arg)
	printf("Thread cleanup handler called.\n");

void *
selector(void *arg)
	fd_set fds;
	int ret;

	printf("Thread started\n");
	while (!done) {
		FD_SET(2, &fds);	/* stderr */
		pthread_cleanup_push(cleanup, NULL);
		ret = select(3, &fds, NULL, NULL, NULL);
		printf("select returned %d, errno %d\n", ret, errno);

	return (NULL);

	pthread_t t;

	pthread_create(&t, NULL, selector, NULL);
	pthread_join(t, NULL);
	return (0);


More information about the freebsd-threads mailing list