Initializes a semaphore in a mapped file or shared memory region.
#include <sys/mman.h>
msemaphore *msem_init ( Sem, InitialValue)
msemaphore *Sem;
int InitialValue;
The msem_init subroutine allocates a new binary semaphore and initializes the state of the new semaphore.
If the value of the InitialValue parameter is MSEM_LOCKED, the new semaphore is initialized in the locked state. If the value of the InitialValue 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 subroutine and having both read and write access.
Whether a semaphore is created in a mapped file or in an anonymous shared memory region, any reference by a process that has mapped the same file or shared region, using an msemaphore structure pointer that resolved to the same file or start of region offset, is taken as a reference to the same semaphore.
Any previous semaphore state stored in the msemaphore structure is ignored and overwritten.
Sem | Points to an msemaphore structure in which the state of the semaphore is stored. |
Initial Value | Determines whether the semaphore is locked or unlocked at allocation. |
When successful, the msem_init subroutine returns a pointer to the initialized msemaphore structure. Otherwise, it returns a null value and sets the errno global variable to indicate the error.
If the msem_init
subroutine is unsuccessful, the errno global variable is set to one
of the following values:
EINVAL | Indicates the InitialValue parameter is not valid. |
ENOMEM | Indicates a new semaphore could not be created. |
The msem_init subroutine is part of Base Operating System (BOS) Runtime.
The mmap (mmap or mmap64 Subroutine) subroutine, msem_lock (msem_lock Subroutine) subroutine, msem_remove (msem_remove Subroutine) subroutine, msem_unlock (msem_unlock Subroutine) subroutine.
List of Memory Mapping Services and Understanding Memory Mapping in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.