From owner-freebsd-current@FreeBSD.ORG Thu Dec 3 00:37:07 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0AF0E1065670; Thu, 3 Dec 2009 00:37:07 +0000 (UTC) (envelope-from gallatin@cs.duke.edu) Received: from duke.cs.duke.edu (duke.cs.duke.edu [152.3.140.1]) by mx1.freebsd.org (Postfix) with ESMTP id A9A0B8FC08; Thu, 3 Dec 2009 00:37:06 +0000 (UTC) Received: from grapeape1.cs.duke.edu (grapeape1.cs.duke.edu [152.3.140.75]) by duke.cs.duke.edu (8.14.2/8.14.2) with ESMTP id nB30b6No011920 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 2 Dec 2009 19:37:06 -0500 (EST) Received: (from gallatin@localhost) by grapeape1.cs.duke.edu (8.12.10/8.12.10/Submit) id nB30b5ja001795; Wed, 2 Dec 2009 19:37:05 -0500 (EST) Date: Wed, 2 Dec 2009 19:37:05 -0500 From: Andrew Gallatin To: Daniel Eischen Message-ID: <20091203003705.GA1769@grapeape1.cs.duke.edu> References: <4B16D802.6030904@cs.duke.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Operating-System: SunOS 5.10 on an sun4u User-Agent: Mutt/1.5.13 (2006-08-11) Cc: freebsd-current@freebsd.org Subject: Re: process shared semaphores? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Dec 2009 00:37:07 -0000 Daniel Eischen [deischen@freebsd.org] wrote: > On Wed, 2 Dec 2009, Andrew Gallatin wrote: > > > > >The man page for sem_init(3) says: > > > > A non-zero value for pshared specifies a > > shared semaphore that can be used by multiple processes, which this > > implementation is not capable of. > > > >Is this still correct? I'm asking, both because it seems strange to > >not return an error if the implementation does not support pshared > >semaphores, and because the threads library seems to expect > >it to work. Eg: > > > >int > >_sem_init(sem_t *sem, int pshared, unsigned int value) > >{ > > semid_t semid; > > > > semid = (semid_t)SEM_USER; > > if ((pshared != 0) && (ksem_init(&semid, value) != 0)) > > return (-1); > ><.... > > > > > >So is the man page out of date, or is the userspace code future-proof > >for when the kernel catches up? > > The code should probably return -1 and ENOTSUP. > > Why don't you use named semaphores if you want > process shared (sem_open)? Shouldn't those work? To be honest, I didn't know they even existed. I'm mostly a driver guy, and know little about user-space. I'm trying to keep up FreeBSD support on a project that is being developed mainly on Linux. I've suggested them to our main developer. In the meantime, I'd like to understand what's going on under the hood, and why what we're doing now on Linux (semaphore resides in shared memory allocated with shm_open) wouldn't work. It looks like it should work, since with pshared semaphores, it just passes everything through to ksem*. Is problem that the kernel doesn't really know about different processes using it? Eg, it has only seen a ksem_init() from the server, which did the sem_init(), and it needs the ksem_open() to know about other processes using it? Thanks, Drew