From owner-freebsd-hackers Wed Sep 18 18:34:18 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 34E4937B401; Wed, 18 Sep 2002 18:34:17 -0700 (PDT) Received: from avocet.mail.pas.earthlink.net (avocet.mail.pas.earthlink.net [207.217.120.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id CE45B43E3B; Wed, 18 Sep 2002 18:34:16 -0700 (PDT) (envelope-from tlambert2@mindspring.com) Received: from pool0424.cvx21-bradley.dialup.earthlink.net ([209.179.193.169] helo=mindspring.com) by avocet.mail.pas.earthlink.net with esmtp (Exim 3.33 #1) id 17rqCs-0004fj-00; Wed, 18 Sep 2002 18:34:14 -0700 Message-ID: <3D89290A.B05D1882@mindspring.com> Date: Wed, 18 Sep 2002 18:31:54 -0700 From: Terry Lambert X-Mailer: Mozilla 4.79 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: Alfred Perlstein Cc: hackers@freebsd.org, deischen@freebsd.org, Garrett Wollman Subject: Re: sem_init help? References: <20020919005959.GO86737@elvis.mu.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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 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. > 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. 8-). -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message