Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Fri, 20 Apr 2001 15:03:25 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Fri, 20 Apr 2001 15:03:16 -0400 Received: from quechua.inka.de ([212.227.14.2]:5898 "EHLO mail.inka.de") by vger.kernel.org with ESMTP id ; Fri, 20 Apr 2001 15:03:11 -0400 To: Jesse Pollard cc: linux-kernel@vger.kernel.org Subject: Re: light weight user level semaphores In-Reply-To: Your message of "Fri, 20 Apr 2001 09:19:37 CDT." <200104201419.JAA50024@tomcat.admin.navo.hpc.mil> In-Reply-To: <200104201419.JAA50024@tomcat.admin.navo.hpc.mil> X-Face: /`ST`Hv?*sL!s'S6-'gR0$/LS9x}Oa+7#rIM@#?5]HrLuXUuYw|!B(WX5(P_V>5EcrDvF?@ qvu]'$2hWLlpq+/}@Q0We<(,[FZ_S^CY>yKfnPM;GU#psKPG/.+KaG{qDd=}Ak_=|ATIBWpccF^*u^ 0N+a8|4f^?uJKKQLDA$%^kwjgmLO`TOxsAsj}tX=eW"Ll8yxD1O{_G[F/+wjwvq1e*[uyhRp-d:V?x $PtI{{(~k(:jV|Pb>"uvMJ8Z$,.\V>EF9I# Mime-Version: 1.0 (generated by tm-edit 1.5) Content-Type: text/plain; charset=US-ASCII Date: Fri, 20 Apr 2001 20:36:42 +0200 From: Olaf Titz Message-Id: Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org > Optimization use in select: If all "interesting" file id's are known > to be below "n", then only the first "n" bits in a FD_ISSET need to > be examined. As soon as the bits are scattered, it takes MUCH longer > to check for activity.... That's an optimization, not a correctness issue. > for (i = 0; i <= MAX_LOG && i < argc; i++) { > sprintf(str,"/tmp/%s",pnames[i]); > mkfifo(str,0600); /* assume it exists */ > inlogfd[i] = open(str,O_RDONLY | O_NDELAY); > FD_SET(inlogfd[i],&in_files); > } This works regardless of what the open() returns. What does not work is using MAX_LOG (assuming it is constant) later in the following form: > while (select(MAX_LOG,&active,NULL,NULL,NULL) >= 0) { I see no way around computing the maximum of the inlogfd[i] values +1. (Which can of course be done just after the opens above. Note that the last opened fd _is_ guaranteed to get the highest number; FD_SET is one of the library routines where you can be pretty confident they don't open fds...) Btw. there are two problems even assuming you do get contiguous fds: - an off by one error in the case of argc > MAX_LOG, the first argument of select() is maximum fd _plus one_ - from an optimization POV it is highly advisable to take only the real maximum anyway. Olaf - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/