Date: Sat, 29 Jan 2005 13:23:47 -0500 (EST) From: Daniel Eischen <deischen@freebsd.org> To: Niall Douglas <s_sourceforge@nedprod.com> Cc: freebsd-threads@freebsd.org Subject: Re: Trying again: select() should be a cancellation point Message-ID: <Pine.GSO.4.43.0501291300560.17542-100000@sea.ntplx.net> In-Reply-To: <41FB9E30.1726.48C69D9F@localhost>
index | next in thread | previous in thread | raw e-mail
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_ZERO(&fds);
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);
pthread_cleanup_pop(0);
}
return (NULL);
}
int
main(void)
{
pthread_t t;
pthread_create(&t, NULL, selector, NULL);
sleep(2);
pthread_cancel(t);
sleep(1);
pthread_join(t, NULL);
return (0);
}
--
DE
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.43.0501291300560.17542-100000>
