Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

msem_init(3) [osf1 man page]

msem_init(3)						     Library Functions Manual						      msem_init(3)

NAME
msem_init - Initializes a semaphore in a mapped file or shared memory region LIBRARY
Standard C Library (libc.a) SYNOPSIS
#include <sys/mman.h> msemaphore *msem_init ( msemaphore *sem, int initial_value ); PARAMETERS
Points to an msemaphore structure in which the state of the semaphore is stored. Determines whether the semaphore is locked or unlocked at allocation. DESCRIPTION
The msem_init() function allocates a new binary semaphore and initializes the state of the new semaphore. If the initial_value parameter is MSEM_LOCKED, the new semaphore is initialized in the locked state. If the initial_value parameter is MSEM_UNLOCKED, the new semaphore is initialized in the unlocked state. The msemaphore structure is located within a mapped file or shared memory region created by a successful call to the mmap() function and having both read and write access. If a semaphore is created in a mapped file region, any reference by a process which has mapped the same file, using a (struct msemaphore *) pointer which resolves to the same file offset, is taken as a reference to the same semaphore. If a semaphore is created in an anonymous shared memory region, any reference by a process which shares the same region, using a (struct msemaphore *) pointer which resolves to the same offset from the start of the region, is taken as a reference to the same semaphore. Any previous semaphore state stored in the msemaphore structure is ignored and overwritten. NOTES
Trial use RETURN VALUES
Upon successful completion, the msem_init() function returns a pointer to the initialized msemaphore structure. On error, the msem_init() function returns null and sets errno to indicate the error. ERRORS
If the msem_init() function fails, errno may be set to one of the following values: The initial_value parameter is not valid. A new sema- phore could not be created. RELATED INFORMATION
Functions: mmap(2), msem_lock(3), msem_remove(3), msem_unlock(3) delim off msem_init(3)

Check Out this Related Man Page

msem_init(2)							System Calls Manual						      msem_init(2)

NAME
msem_init - initialize a semaphore in a mapped file or anonymous memory region SYNOPSIS
DESCRIPTION
allocates a new binary semaphore and initializes the state of the new semaphore. sem points to an structure in which the state of the semaphore is to be stored. If initial_value is the new semaphore is initialized in the locked state. If initial_value is the new semaphore is initialized in the unlocked state. The structure must be located within a mapped file or anonymous memory region created by a successful call to and have both read and write access. If a semaphore is created in a mapped file region, any reference by a process that has mapped the same file, using a pointer that resolves to the same file offset is interpreted as a reference to the same semaphore. If a semaphore is created in an anonymous memory region, any reference by a process sharing the same region by use of a pointer that resolves to the same offset from the start of the region is inter- preted as a reference to the same semaphore. Any previous semaphore state stored in the structure will be ignored and overwritten. Implementation Notes In order to ensure that an structure is entirely contained in a single memory page, sem must be at an address that is an exact multiple of The size of the structure is guaranteed to prevent semaphores that cross page boundaries given the above restriction. For a memory mapped file region, the system deallocates memory that corresponds to a range of the file that has been truncated with or If a semaphore is located in memory so deallocated, the effect is equivalent to an on the semaphore. RETURN VALUE
returns the address of the initialized structure; otherwise, it returns NULL and sets to indicate the error. ERRORS
fails if any of the following conditions are encountered: sem points to an structure that is not located in a mapped region created by and with read and write access, or ini- tial_value is not valid. A new semaphore could not be created. sem is an invalid pointer. AUTHOR
was developed by HP and OSF. SEE ALSO
mmap(2), msem_lock(2), msem_remove(2), msem_unlock(2), mman(5). STANDARDS CONFORMANCE
msem_init(2)
Man Page