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

sem_init(2)							System Calls Manual						       sem_init(2)

NAME
sem_init - initialize an unnamed POSIX semaphore SYNOPSIS
DESCRIPTION
is used to initialize an unnamed semaphore. A successful call to will create a new unnamed semaphore referred to by sem, if one does not exist, initialize the unnamed semaphore descriptor, referred to by sem, to the non-negative value specified by value. If the unnamed sema- phore already exists, i.e. created by a previous call to it is re-initialized only if its current value is equal to its initial value (set by the last successful call to If so, the initial value of the unnamed semaphore is re-initialized to the value argument. Otherwise, the call fails. The argument pshared specifies if the unnamed semaphore is sharable with other processes. If pshared is equal to 0, the unnamed semaphore is not shared with other processes. If pshared is non-zero, the unnamed semaphore is sharable with any processes that can access sem. The access mode specified for the unnamed semaphore allows read and write permissions to all processes. If the calling process may attach to the shared structure, it is assumed it may operate on the semaphore. To use this function, link in the realtime library by specifying on the compiler or linker command line. EXAMPLES
The following call to will create a new unnamed semaphore referred to by sem, if one does not exist, initialize the unnamed semaphore descriptor, referred to by sem, to the non-negative value specified by value. RETURN VALUE
If the semaphore was created and initialized, returns 0 to the caller. If the semaphore could not be created/initialized, the call returns -1 and sets to indicate the error. ERRORS
fails and does not perform the requested operation if any of the following conditions are encountered: [EPERM] The calling process does not have the privileges necessary to initialize the semaphore. [EBUSY] There are threads currently blocked on the semaphore or there are outstanding locks held on the semaphore. [EINVAL] The argument value is greater than [ENOSPC] There are insufficient resources to perform the operation or the upper limit on the number of semaphores is reached. SEE ALSO
sem_destroy(2), sem_post(2), sem_trywait(2), sem_wait(2), <semaphore.h>. STANDARDS CONFORMANCE
sem_init(2)
Man Page