From owner-freebsd-threads@FreeBSD.ORG Fri Feb 25 11:34:26 2005 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B43C116A4CE; Fri, 25 Feb 2005 11:34:26 +0000 (GMT) Received: from cyrus.watson.org (cyrus.watson.org [204.156.12.53]) by mx1.FreeBSD.org (Postfix) with ESMTP id 636D043D31; Fri, 25 Feb 2005 11:34:26 +0000 (GMT) (envelope-from robert@fledge.watson.org) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by cyrus.watson.org (Postfix) with SMTP id 89EE046B2C; Fri, 25 Feb 2005 06:34:25 -0500 (EST) Date: Fri, 25 Feb 2005 11:32:39 +0000 (GMT) From: Robert Watson X-Sender: robert@fledge.watson.org To: Daniel Eischen In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: threads@freebsd.org cc: alfred@freebsd.org Subject: Re: POSIX semaphores and fork() -- when any process exits, they all lose , access X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Feb 2005 11:34:26 -0000 On Thu, 24 Feb 2005, Daniel Eischen wrote: > > If I create a named POSIX semaphore in a process, then fork(), the > > semaphore appears to be visible to both the parent and child. However, as > > soon as the child exits, the semaphore disappears from the parent. This > > seems likely incorrect, although I don't have a copy of the spec in > > question so couldn't say for sure. > > http://www.opengroup.org/onlinepubs/009695399/functions/sem_open.html Hmm. I haven't yet found a reference to fork() semantics for semaphores in the semaphore-related pages. However, a bit of googling turned up the following references: - HIP's Tru64 documentation includes the words: "The semaphore descriptor is inherited across a fork. A parent process can create a semaphore, open it, and fork. The child process does not need to open the semaphore and can close the semaphore if the application is finished with it." So it sounds like the semaphore references for a process basically need to be replicated for the child. One hesitates to guess how this will interact with things like Linux threading. The glibc POSIX semaphores documentation doesn't mention sem_open()/sem_close(), so maybe they only do semaphores in the context of the user thread library, and not inter-process semaphores. Thanks, Robert N M Watson