Trying again: select() should be a cancellation point
Daniel Eischen
deischen at freebsd.org
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_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
More information about the freebsd-threads
mailing list