From owner-freebsd-hackers Wed Sep 18 18:44:26 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 95D7E37B401; Wed, 18 Sep 2002 18:44:24 -0700 (PDT) Received: from mail.pcnet.com (pcnet1.pcnet.com [204.213.232.3]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1467D43E65; Wed, 18 Sep 2002 18:44:24 -0700 (PDT) (envelope-from eischen@pcnet1.pcnet.com) Received: from localhost (eischen@localhost) by mail.pcnet.com (8.12.3/8.12.1) with ESMTP id g8J1iNoQ002454; Wed, 18 Sep 2002 21:44:23 -0400 (EDT) Date: Wed, 18 Sep 2002 21:44:23 -0400 (EDT) From: Daniel Eischen To: Terry Lambert Cc: Alfred Perlstein , hackers@FreeBSD.org, deischen@FreeBSD.org, Garrett Wollman Subject: Re: sem_init help? In-Reply-To: <3D89290A.B05D1882@mindspring.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Wed, 18 Sep 2002, Terry Lambert wrote: > Alfred Perlstein wrote: > > Ok, any of you guys have a copy of the standards documents that > > describe the sem_* API? > > > > I have a question... > > > > What are the semantics of the sem_init when pshared is set to true? > > The sem_init() function is used to initialise the unnamed > semaphore referred to by sem. The value of the initialised > semaphore is value. Following a successful call to sem_init(), > the semaphore may be used in subsequent calls to sem_wait(), > sem_trywait(), sem_post(), and sem_destroy(). This semaphore > remains usable until the semaphore is destroyed. > > If the pshared argument has a non-zero value, then the > semaphore is shared between processes; in this case, any > process that can access the semaphore sem can use sem for > performing sem_wait(), sem_trywait(), sem_post(), and > sem_destroy() operations. > > Only sem itself may be used for performing synchronisation. > The result of referring to copies of sem in calls to > sem_wait(), sem_trywait(), sem_post(), and sem_destroy(), is > undefined. > > If the pshared argument is zero, then the semaphore is shared > between threads of the process; any thread in this process can > use sem for performing sem_wait(), sem_trywait(), sem_post(), > and sem_destroy() operations. The use of the semaphore by > threads other than those created in the same process is > undefined. > > Attempting to initialise an already initialised semaphore > results in undefined behaviour. > > > Like, if the process that created the semaphore exits, then what? > > The use of the semaphore by threads other than those created > in the same process is undefined. Terry, your forgot to prefix that with "If the pshared argument is zero". Alfred's concerned with pshared != 0. > > Is it only valid for the life of the process that did the sem_init? > > The use of the semaphore by threads other than those created > in the same process is undefined. Same here. -- Dan Eischen To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message