From owner-freebsd-hackers@FreeBSD.ORG Fri Oct 23 15:45:52 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D24D3106566C; Fri, 23 Oct 2009 15:45:52 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 8FB598FC17; Fri, 23 Oct 2009 15:45:52 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 2568146B53; Fri, 23 Oct 2009 11:45:52 -0400 (EDT) Received: from jhbbsd.hudson-trading.com (unknown [209.249.190.8]) by bigwig.baldwin.cx (Postfix) with ESMTPA id 42CD18A01F; Fri, 23 Oct 2009 11:45:51 -0400 (EDT) From: John Baldwin To: Daniel Eischen Date: Fri, 23 Oct 2009 11:36:21 -0400 User-Agent: KMail/1.9.7 References: <4AE0BBAB.3040807@cs.duke.edu> <200910230802.49873.jhb@freebsd.org> In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200910231136.21837.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Fri, 23 Oct 2009 11:45:51 -0400 (EDT) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=4.2 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: freebsd-hackers@freebsd.org, Andrew Gallatin , Christian Bell Subject: Re: semaphores between processes X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Oct 2009 15:45:53 -0000 On Friday 23 October 2009 10:56:06 am Daniel Eischen wrote: > On Fri, 23 Oct 2009, John Baldwin wrote: > > > On Thursday 22 October 2009 5:17:07 pm Daniel Eischen wrote: > >> On Thu, 22 Oct 2009, Andrew Gallatin wrote: > >> > >>> Daniel Eischen wrote: > >>>> On Thu, 22 Oct 2009, Andrew Gallatin wrote: > >>>> > >>>>> Hi, > >>>>> > >>>>> We're designing some software which has to lock access to > >>>>> shared memory pages between several processes, and has to > >>>>> run on Linux, Solaris, and FreeBSD. We were planning to > >>>>> have the lock be a pthread_mutex_t residing in the > >>>>> shared memory page. This works well on Linux and Solaris, > >>>>> but FreeBSD (at least 7-stable) does not support > >>>>> PTHREAD_PROCESS_SHARED mutexes. > >>>>> > >>>>> We then moved on to posix semaphores. Using sem_wait/sem_post > >>>>> with the sem_t residing in a shared page seems to work on > >>>>> all 3 platforms. However, the FreeBSD (7-stable) man page > >>>>> for sem_init(3) has this scary text regarding the pshared > >>>>> value: > >>>>> > >>>>> The sem_init() function initializes the unnamed semaphore pointed to > >>>>> by > >>>>> sem to have the value value. 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 text obsolete? Or is my test just "getting lucky"? > >>>> > >>>> I think you're getting lucky. > >>> > >>> Yes, after playing with the code some, I now see that. :( > >>> > >>>>> Is there recommended way to do this? > >>>> > >>>> I believe the only way to do this is with SYSV semaphores > >>>> (semop, semget, semctl). Unfortunately, these are not as > >>>> easy to use, IMHO. > >>> > >>> Yes, they are pretty ugly, and we were hoping to avoid them. > >>> Are there any plans to support either PTHREAD_PROCESS_SHARED > >>> mutexes, or pshared posix semaphores in FreeBSD? > >> > >> It's planned, just not (yet) being actively worked on. > >> It's a API change mostly, and then adding in all the > >> compat hooks so we don't break ABI. > > > > There are also an alternate set of patches on threads@ to allow just shared > > semaphores I think w/o the changes to the pthread types. I can't recall > > exactly what they did, but I think rrs@ was playing with using umtx directly > > to implement some sort of process-shared primitive. > > That's really not the way to go. The structs really need > to become public. I was mostly suggesting it as a way to use something sooner since I expect it will be a long while before anyone does the pthreads work. -- John Baldwin