From owner-freebsd-threads@FreeBSD.ORG Sat Jan 29 18:23:49 2005 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4B5B516A4CE for ; Sat, 29 Jan 2005 18:23:49 +0000 (GMT) Received: from mail.ntplx.net (mail.ntplx.net [204.213.176.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id E778E43D31 for ; Sat, 29 Jan 2005 18:23:48 +0000 (GMT) (envelope-from deischen@freebsd.org) Received: from sea.ntplx.net (sea.ntplx.net [204.213.176.11]) j0TINluK021948; Sat, 29 Jan 2005 13:23:47 -0500 (EST) Date: Sat, 29 Jan 2005 13:23:47 -0500 (EST) From: Daniel Eischen X-X-Sender: eischen@sea.ntplx.net To: Niall Douglas In-Reply-To: <41FB9E30.1726.48C69D9F@localhost> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS and Clam AntiVirus (mail.ntplx.net) cc: freebsd-threads@freebsd.org Subject: Re: Trying again: select() should be a cancellation point X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Daniel Eischen List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Jan 2005 18:23:49 -0000 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 #include #include #include #include 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