Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

msem_lock(3) [osf1 man page]

msem_lock(3)						     Library Functions Manual						      msem_lock(3)

NAME
msem_lock - Locks a semaphore LIBRARY
Standard C Library (libc.a) SYNOPSIS
#include <sys/mman.h> int msem_lock ( msemaphore *sem, int condition ); PARAMETERS
Points to an msemaphore structure which specifies the semaphore to be locked. Determines whether the msem_lock() function waits for a cur- rently locked semaphore to unlock. DESCRIPTION
The msem_lock() function attempts to lock a binary semaphore. If the semaphore is not currently locked, it is locked and the msem_lock() function returns successfully. If the semaphore is currently locked, and the condition parameter is MSEM_IF_NOWAIT, then the msem_lock() function returns with an error. If the semaphore is currently locked, and the condition parameter is 0 (zero), then msem_lock() will not return until either the calling process is able to successfully lock the semaphore, or an error condition occurs. All calls to msem_lock() and msem_unlock() by multiple processes sharing a common msemaphore structure behave as if the calls were serial- ized. If the msemaphore structure contains any value not resulting from a call to msem_init() followed by a (possibly empty) sequence of calls to msem_lock() and msem_unlock(), the results are undefined. The address of an msemaphore structure may be significant. If the msemaphore structure contains any value copied from an msemaphore structure at a different address, the result is undefined. NOTES
Trial use RETURN VALUES
On successful completion, the msem_lock() function returns 0 (zero). On error, the msem_lock() function returns -1 and sets errno to indi- cate the error. ERRORS
If the msem_lock() function fails, errno may be set to one of the following values: MSEM_IF_NOWAIT was specified and the semaphore was already locked. The sem parameter points to an msemaphore structure which specifies a semaphore which has been removed, or the condition parameter is invalid. The msem_lock() function was interrupted by a signal which was caught. RELATED INFORMATION
Functions: msem_init(3), msem_remove(3), msem_unlock(3) delim off msem_lock(3)

Check Out this Related Man Page

sem_wait(2)							System Calls Manual						       sem_wait(2)

NAME
sem_wait, sem_trywait - lock a POSIX semaphore SYNOPSIS
DESCRIPTION
is used to lock a semaphore. The calling thread will not return from its call to until one of the following events occur: it successfully obtains a lock on the semaphore; it is interrupted by a signal or an error condition occurs. is used to lock a semaphore, if it is available. The value of the semaphore sem is checked at some unspecified time during the call. If the semaphore is available at the time its value is checked, the calling thread will atomically, with respect to the checking of the value, lock the semaphore. The thread will now own a lock on the semaphore; the call will return successfully. If the semaphore is unavailable at the time its value is checked, then the call returns -1 with errno set to EAGAIN. If the specified semaphore referred to by sem is a named semaphore, then this semaphore must have been opened by the calling process with The calling process must have both read and write permissions on the semaphore to perform these operations. The semaphore will be locked upon successful return and will stay locked until it is explicitly released by a call to To use this function, link in the realtime library by specifying on the compiler or linker command line. EXAMPLES
The following call to will lock the semaphore sem. The following call to will lock the semaphore sem, if it is available. RETURN VALUE
A successful call to will return 0 and the calling thread will then own a lock on the semaphore. Otherwise, the call to will return -1 with errno set to the appropriate value of the error condition. A successful call to will return 0, if the semaphore was available and the calling thread was able to lock the semaphore. Otherwise, the call to will return -1 with errno set to the appropriate value of the error condition. ERRORS
and fail and do not perform the requested operation if any of the following conditions are encountered: [EPERM] The calling process does not have the privileges necessary to lock the semaphore. [EAGAIN] The semaphore was not available and hence could not be locked by This error condition only occurs in [EINVAL] The argument sem does not refer to a valid semaphore. [EINTR] The function was interrupted by a signal SEE ALSO
sem_post(2), <semaphore.h>. STANDARDS CONFORMANCE
sem_wait(2)
Man Page