Locks a semaphore.
Standard C Library (libc.a)
int msem_lock ( Sem, Condition)
The msem_lock subroutine attempts to lock a binary semaphore.
If the semaphore is not currently locked, it is locked and the msem_lock subroutine completes successfully.
If the semaphore is currently locked, and the value of the Condition parameter is MSEM_IF_NOWAIT, the msem_lock subroutine returns with an error. If the semaphore is currently locked, and the value of the Condition parameter is 0, the msem_lock subroutine does not return until either the calling process is able to successfully lock the semaphore or an error condition occurs.
All calls to the msem_lock and msem_unlock subroutines by multiple processes sharing a common msemaphore structure behave as if the call were serialized.
If the msemaphore structure contains any value not resulting from a call to the msem_init subroutine, followed by a (possibly empty) sequence of calls to the msem_lock and msem_unlock subroutines, the results are undefined. The address of an msemaphore structure is significant. If the msemaphore structure contains any value copied from an msemaphore structure at a different address, the result is undefined.
|Sem||Points to an msemaphore structure that specifies the semaphore to be locked.|
|Condition||Determines whether the msem_lock subroutine waits for a currently locked semaphore to unlock.|
When successful, the msem_lock subroutine returns a value of 0. Otherwise, it returns a value of -1 and sets the errno global variable to indicate the error.
If the msem_lock
subroutine is unsuccessful, the errno global variable is set to one
of the following values:
|EAGAIN||Indicates a value of MSEM_IF_NOWAIT is specified for the Condition parameter and the semaphore is already locked.|
|EINVAL||Indicates the Sem parameter points to an msemaphore structure specifying a semaphore that has been removed, or the Condition parameter is invalid.|
|EINTR||Indicates the msem_lock subroutine was interrupted by a signal that was caught.|
The msem_lock subroutine is part of Base Operating System (BOS) Runtime.
The msem_init (msem_init 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.