From owner-freebsd-hackers Mon Aug 13 10:33:33 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from net2.gendyn.com (nat2.gendyn.com [204.60.171.12]) by hub.freebsd.org (Postfix) with ESMTP id 084C237B407; Mon, 13 Aug 2001 10:33:24 -0700 (PDT) (envelope-from eischen@vigrid.com) Received: from [153.11.11.3] (helo=plunger.gdeb.com) by net2.gendyn.com with esmtp (Exim 2.12 #1) id 15WLaV-000EWv-00; Mon, 13 Aug 2001 13:33:15 -0400 Received: from clcrtr.gdeb.com ([153.11.109.11]) by plunger.gdeb.com with ESMTP id NAA29197; Mon, 13 Aug 2001 13:31:22 -0400 (EDT) Received: from vigrid.com (clcrtr1.clc.gdeb.com [153.11.109.149]) by clcrtr.gdeb.com (8.11.4/8.11.4) with ESMTP id f7DHW8K16540; Mon, 13 Aug 2001 13:32:09 -0400 (EDT) (envelope-from eischen@vigrid.com) Message-ID: <3B780BFC.F2BA0A9B@vigrid.com> Date: Mon, 13 Aug 2001 13:18:52 -0400 From: "Daniel M. Eischen" X-Mailer: Mozilla 4.51 [en] (X11; U; FreeBSD 3.2-STABLE i386) X-Accept-Language: en MIME-Version: 1.0 To: Jonathan Chen Cc: hackers@freebsd.org Subject: Re: pthreads and poll() References: <20010813120455.A63309@enterprise.spock.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 Jonathan Chen wrote: > Yesterday marked my first attempt at mixing poll() with pthreads. > Needless to say, things did not work out the way I wanted them to. So, I > began the task of finding out the behaviors of various OSes to see if my > code would run fine on them. For your reference and amusement, my results > and test code is included below. > > I think that waking only one thread up is the correct behavior, or is there > something that toggles which behavior I want? Perhaps someone with access > to the POSIX standard would care to confirm what the Right Thing is? > Perhaps that someone would then proceed to fix all the incorrect > implementations... or am I asking too much? :) > > Looks like I'm going to have to swear off mixing poll() with pthreads for > at least two years if I want my code to be portable... We don't provide locking for fd's any longer (I thought this was only in -current, but your results seem to indicate otherwise). If we did, only one thread would wake up. The mistake in your sample seems to be that you're having all threads block on the same fd. Why? We took the approach in -current that it is up to the application to provide locking for fd's. Our libc_r also wraps poll() into non-blocking calls which allows the other threads to run and "block" on the same fd. When we get blocking down in the kernel (KSEs or a linuxthreads like approach), I'm not exactly sure what would happen. From your results (linuxthreads under FreeBSD), it looks like it should behave as you expect. > Aside: I thought that linuxthreads == Linux's implementation of pthreads? > Now why do they behave differently? It depends on how things get woken up in the kernel. I don't think I would rely on any particular behaviour... -- Dan Eischen To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message