From owner-freebsd-hackers Tue Oct 22 8:28:18 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D420F37B401 for ; Tue, 22 Oct 2002 08:28:16 -0700 (PDT) Received: from mail.pcnet.com (mail.pcnet.com [204.213.232.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id 55CE743E3B for ; Tue, 22 Oct 2002 08:28:16 -0700 (PDT) (envelope-from eischen@pcnet1.pcnet.com) Received: from localhost (eischen@localhost) by mail.pcnet.com (8.12.3/8.12.1) with ESMTP id g9MFSBp9025145; Tue, 22 Oct 2002 11:28:12 -0400 (EDT) Date: Tue, 22 Oct 2002 11:28:11 -0400 (EDT) From: Daniel Eischen To: Peter Pentchev Cc: Bruce M Simpson , freebsd-hackers@FreeBSD.ORG Subject: Re: PThreads problem In-Reply-To: <20021022123038.GB378@straylight.oblivion.bg> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Tue, 22 Oct 2002, Peter Pentchev wrote: > On Tue, Oct 22, 2002 at 12:31:32PM +0100, Bruce M Simpson wrote: > > On Mon, Oct 21, 2002 at 02:03:52PM -0700, Terry Lambert wrote: > > > It is more correct to say that libcurl makes an assumption about > > > signal delivery which is not guaranteed by POSIX, and therefore > > > libcurl will not work with *any* POSIX compliant threads > > > implementation which does not *happen* to work this way. > > > > Would a more correct approach, when dealing with POSIX threads and signals, > > be to make sure signals are delivered to a single thread *expressly for > > that purpose*, and then use POSIX thread primitives (such as mutexes and > > condvars) to communicate the signal conditions to the other threads? > > ..and when you start writing programs which depend on this functionality, > they will not work on any system that does not do it. Part of the problem > is that the linuxthreads approach of different threads as different > processes would require that you deliver each and every signal destined > for a 'worker' thread/process to the designated 'signal handler' > thread/process; I am practically certain that no one in the Linux kernel > crowd would like the idea of redirecting all signals from one process to > another :) Like it or not, what Bruce is suggesting is POSIX behaviour. If Linuxthreads doesn't allow one thread to sigwait or sisgsuspend on a signal, and to have a signal delivered to it (assuming the signal is masked in all other threads), then it is very wrong. Plus, each client thread doesn't necessarily have to do the sigalarm() itself. The timeout server thread can do it based on the smallest timeout in its list of client requests. When a new thread wants to add a timeout, it locks the timeout list, inserts the timeout, unlocks the list, and uses pthread_kill(tsid, SIGALRM) to wakeup the timeout server thread. When the timeout server thread wakes up, it can reevaluate its list of timeout requests, handle any threads that have timed out, and go back to sleep. You can use pthread_kill() to signal any client thread that has timedout. I'm sure there are other ways of doing it, but I don't see why something like the above won't work under Linuxthreads as well. -- Dan Eischen To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message