From owner-freebsd-current Mon Aug 7 11:34:20 2000 Delivered-To: freebsd-current@freebsd.org Received: from critter.freebsd.dk (flutter.freebsd.dk [212.242.40.147]) by hub.freebsd.org (Postfix) with ESMTP id 3056037B94A; Mon, 7 Aug 2000 11:34:11 -0700 (PDT) (envelope-from phk@critter.freebsd.dk) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.9.3/8.9.3) with ESMTP id UAA10528; Mon, 7 Aug 2000 20:34:03 +0200 (CEST) (envelope-from phk@critter.freebsd.dk) To: Alfred Perlstein Cc: Matt Dillon , Mike Smith , Stephen McKay , freebsd-current@FreeBSD.ORG, dillon@FreeBSD.ORG Subject: Re: Ugly, slow shutdown In-Reply-To: Your message of "Mon, 07 Aug 2000 11:26:12 PDT." <20000807112612.V4854@fw.wintelcom.net> Date: Mon, 07 Aug 2000 20:34:03 +0200 Message-ID: <10526.965673243@critter.freebsd.dk> From: Poul-Henning Kamp Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG In message <20000807112612.V4854@fw.wintelcom.net>, Alfred Perlstein writes: >> Then this code should be changed to do the right thing, which is >> to *always* check the condition being slept on before proceeding. > >Can you give a reason why we'll have to now start coding defensively >because our arguments to tsleep() are just "advisory" now? It is not something we "suddenly have to do" it's been The Right Way even since I first sharpened my teeth on unix kernels many years ago. Coding defensively btw, is in the same category :-) >I can also imagine some fun infinite loops like so: > >monitor issues wakeup >producer wakes and terminates or goes away >consumer spins checking on availability This is wrong code. It should be: monitor issues wakeup producer wakes and terminates or goes away consumer spins checking on producer still present and on availability You'll find plenty examples of such code in the tty code. >Also, one must now do this? > > timeo = currenttime + 2; > while (timeo != currenttime) > tsleep(timeo); > >? If the exact duration of your timeout is important, you should always calibrate it against getmicrotime() or getmicrouptime() (depending on it being UTC locked or not). This has also always been the case. -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD coreteam member | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message