Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > M

msem_lock(2)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

msem_lock() — lock a semaphore

SYNOPSIS

#include <sys/mman.h>

int msem_lock( msemaphore *sem, int condition" );

DESCRIPTION

msem_lock() attempts to lock a binary semaphore.

sem points to an msemaphore structure which specifies the semaphore to be locked.

If the semaphore is not currently locked, it becomes locked and the function returns successfully.

If the semaphore is currently locked, and condition is MSEM_IF_NOWAIT, then the function returns with an error. If the semaphore is currently locked and condition is zero, the function does 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 serialized.

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 uniquely identifies the semaphore. If the msemaphore structure contains any value copied from an msemaphore structure at a different address, the result is undefined.

IMPLEMENTATION NOTES

If blocked on a locked semaphore, msem_lock() suspends the calling process at a priority such that the process can be interrupted by a signal.

The system attempts to ignore or recover from invalid values written to the msemaphore structure, but this is not guaranteed for all cases.

msem_lock() successfully acquires a semaphore that is locked by a process that has exited.

RETURN VALUE

msem_lock() returns one of the following values:

0

Success.

-1

Failure. errno is set to indicate the error.

ERRORS

msem_lock() sets errno to one of the following values if the corresponding condition is encountered.

EAGAIN

MSEM_IF_NOWAIT was specified and the semaphore was already locked.

EINVAL

sem points to an msemaphore structure that has been removed, or condition is invalid.

EINTR

msem_lock() was interrupted by a signal that was caught.

EDEADLK

The semaphore is currently locked, condition is zero, and waiting to lock the semaphore would create a deadlock.

EFAULT

sem is not a properly aligned address or is otherwise an invalid pointer.

AUTHOR

msem_lock() was developed by HP and OSF.

STANDARDS CONFORMANCE

msem_lock(): AES

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.