From owner-freebsd-hackers@FreeBSD.ORG Thu Oct 22 21:32:36 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 83F8D106568F for ; Thu, 22 Oct 2009 21:32:36 +0000 (UTC) (envelope-from dudu@dudu.ro) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.154]) by mx1.freebsd.org (Postfix) with ESMTP id 284778FC17 for ; Thu, 22 Oct 2009 21:32:35 +0000 (UTC) Received: by fg-out-1718.google.com with SMTP id d23so3280439fga.13 for ; Thu, 22 Oct 2009 14:32:35 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.5.87 with SMTP id 23mr1957049fau.87.1256245221960; Thu, 22 Oct 2009 14:00:21 -0700 (PDT) In-Reply-To: <4AE0BBAB.3040807@cs.duke.edu> References: <4AE0BBAB.3040807@cs.duke.edu> From: Vlad Galu Date: Fri, 23 Oct 2009 00:00:01 +0300 Message-ID: To: Andrew Gallatin Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-hackers@freebsd.org, 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: Thu, 22 Oct 2009 21:32:36 -0000 On Thu, Oct 22, 2009 at 11:08 PM, Andrew Gallatin wr= ote: > 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. =A0We were planning to > have the lock be a pthread_mutex_t residing in the > shared memory page. =A0This 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. =A0Using sem_wait/sem_post > with the sem_t residing in a shared page seems to work on > all 3 platforms. =A0However, the FreeBSD (7-stable) man page > for sem_init(3) has this scary text regarding the pshared > value: > > =A0 =A0 The sem_init() function initializes the unnamed semaphore pointed= to by > =A0 =A0 sem to have the value value. =A0A non-zero value for pshared spec= ifies a > =A0 =A0 shared semaphore that can be used by multiple processes, which th= is > =A0 =A0 implementation is not capable of. > > Is this text obsolete? =A0Or is my test just "getting lucky"? > > Is there recommended way to do this? > > Thanks, > > Drew Hi Andrew, This works in Linux is because Linux defines sem_t as a struct type(or union, IIRC), while our sem_t is a pointer type (with more state kept in the pointed struct). SYSV semaphores seems the way to go...