Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

msem_init(3)

msem_remove(3)

msem_unlock(3)

MSEM_LOCK(3)                         SysV                         MSEM_LOCK(3)



NAME
     msem_lock - Lock a semaphore

SYNOPSIS
     #include <sys/mman.h>

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

DESCRIPTION
     The msem_lock function attempts to lock a binary semaphore.

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

     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 argument is
     MSEM_IF_NOWAIT, then the msem_lock function returns with an error.  If
     the semaphore is currently locked, and the condition argument 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(3) 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(3) followed by a (possibly empty) sequence of calls to
     msem_lock and msem_unlock(3), 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.

DIAGNOSTICS
     On successful completion, the msem_lock function returns 0 (zero).  On
     error, the msem_lock function returns -1 and sets errno to indicate the
     error.

ERRORS
     msem_lock fails if:

     [EAGAIN]       MSEM_IF_NOWAIT was specified and the semaphore was already
                    locked.

     [EINVAL]       The sem argument points to an msemaphore structure which
                    specifies a semaphore which has been removed, or the
                    condition argument is invalid.

     [EINTR]        The msem_lock function was interrupted by a signal which
                    was caught.

SEE ALSO
     msem_init(3), msem_remove(3), msem_unlock(3), <sys/mman.h>

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026