From owner-freebsd-hackers@FreeBSD.ORG Sun Mar 30 20:04:21 2003 Return-Path: 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 6B15837B401 for ; Sun, 30 Mar 2003 20:04:18 -0800 (PST) Received: from priv-edtnes10-hme0.telusplanet.net (outbound02.telus.net [199.185.220.221]) by mx1.FreeBSD.org (Postfix) with ESMTP id CAC8C43FA3 for ; Sun, 30 Mar 2003 20:04:17 -0800 (PST) (envelope-from sh@planetquake.com) Received: from REASON ([154.5.106.237]) by priv-edtnes10-hme0.telusplanet.netSMTP <20030331040417.ERSR12335.priv-edtnes10-hme0.telusplanet.net@REASON> for ; Sun, 30 Mar 2003 21:04:17 -0700 Message-ID: <009301c2f73a$98d2c970$0300000a@slugabed.org> From: "Sean Hamilton" To: References: <001101c2f71d$8d9e4fb0$0300000a@slugabed.org><20030331023856.GL74971@dan.emsphone.com><007e01c2f730$4b5863d0$0300000a@slugabed.org> <20030331033643.GO74971@dan.emsphone.com> Date: Sun, 30 Mar 2003 20:04:15 -0800 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Subject: Re: wait()/alarm() race condition X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 31 Mar 2003 04:04:22 -0000 Dan Nelson wrote: | In the last episode (Mar 30), Sean Hamilton said: || I'm concerned about this order of events: || || - alarm() || - wait() returns successfully || - if (alarmed...) [false] || - SIGALRM is delivered, alarmed = true || - loop || - wait() waits indefinitely | | A cleaner solution would be to use ualarm(60000,1000) or setitimer() | to do this (replacing the alarm(60) call outside the handler). This looks like the way to go. "cleaner" is certainly relative here, but it's quite likely this hack never comes up in the lifetime of the program. I've inserted a printf just in case. (slight grin) This is my first time dealing with signals... they seem to lack the elegance most of Unix offers. Perhaps that's just my inexperience speaking. sh