Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Sep 2002 21:44:23 -0400 (EDT)
From:      Daniel Eischen <eischen@pcnet1.pcnet.com>
To:        Terry Lambert <tlambert2@mindspring.com>
Cc:        Alfred Perlstein <alfred@FreeBSD.org>, hackers@FreeBSD.org, deischen@FreeBSD.org, Garrett Wollman <wollman@lcs.mit.edu>
Subject:   Re: sem_init help?
Message-ID:  <Pine.GSO.4.10.10209182143040.27827-100000@pcnet1.pcnet.com>
In-Reply-To: <3D89290A.B05D1882@mindspring.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.10.10209182143040.27827-100000>