Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Sep 2002 18:31:54 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Alfred Perlstein <alfred@FreeBSD.org>
Cc:        hackers@freebsd.org, deischen@freebsd.org, Garrett Wollman <wollman@lcs.mit.edu>
Subject:   Re: sem_init help?
Message-ID:  <3D89290A.B05D1882@mindspring.com>
References:  <20020919005959.GO86737@elvis.mu.org>

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D89290A.B05D1882>