From owner-freebsd-hackers Tue Feb 27 4:47:23 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from hda.hda.com (host65.hda.com [63.104.68.65]) by hub.freebsd.org (Postfix) with ESMTP id E3B0937B71A for ; Tue, 27 Feb 2001 04:47:16 -0800 (PST) (envelope-from dufault@hda.hda.com) Received: (from dufault@localhost) by hda.hda.com (8.11.1/8.11.1) id f1RCj5T21997; Tue, 27 Feb 2001 07:45:05 -0500 (EST) (envelope-from dufault) From: Peter Dufault Message-Id: <200102271245.f1RCj5T21997@hda.hda.com> Subject: Re: Where can I find out rules on blocking in threads? In-Reply-To: <200102270121.RAA39980@akira.lanfear.com> from Marc W at "Feb 26, 2001 05:21:37 pm" To: Marc W Date: Tue, 27 Feb 2001 07:43:49 -0500 (EST) Cc: freebsd-hackers@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL61 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > 1. initializes some UI goo (but doesn't start any of it UP) using a > GUI framework (Qt) > 2. creates a FIFO, and then spawns a thread > 3. this new thread then does: > > fifo = open(fifoPath, O_RDONLY); ... > > Now, the problem is that when step 3 above blocks on the open(2) > call (as it should, since the other end of the pipe isn't opened yet), > the whole application is frozen, and the main thread can't continue > with GUI processing, and the app appears to die. > > What is goofy is that this works just fine under Linux. So, > FreeBSD has slightly different blocking rules or something -- but I > don't understand them. It also hangs under Solaris 8/Intel. > > So, the question is: how can I find out what these differences are > and try to get around them. I'm using this to limit instances of my > program to one, and need a named pipe instead of just a lock file so > that new instances can communicate any arguments they might have been > given, etc ... I think the FreeBSD behavior is wrong, the spec says that when opening a FIFO with O_NONBLOCK clear that: > An open() for reading-only shall block the calling thread until a > thread opens the file for writing. An open() for writing-only > shall block the calling thread until a thread opens the file for > reading. The FBSD man pages will let you know if something will block or not, for example, look at the "implementation notes" section for open. You can open the fifo non-blocking and then clear O_NONBLOCK using fcntl, hopefully that will work in all environments. Peter -- Peter Dufault (dufault@hda.com) Realtime development, Machine control, HD Associates, Inc. Fail-Safe systems, Agency approval To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message