msem_unlock Subroutine

Purpose

Unlocks a semaphore.

Library

Standard C Library (libc.a)

Syntax

#include <sys/mman.h>

int msem_unlock ( Sem Condition)
msemaphore *Sem;
int Condition;

Description

The msem_unlock subroutine attempts to unlock a binary semaphore.

If the semaphore is currently locked, it is unlocked and the msem_unlock subroutine completes successfully.

If the Condition parameter is 0, the semaphore is unlocked, regardless of whether or not any other processes are currently attempting to lock it. If the Condition parameter is set to the MSEM_IF_WAITERS value, and another process is waiting to lock the semaphore or it cannot be reliably determined whether some process is waiting to lock the semaphore, the semaphore is unlocked by the calling process. If the Condition parameter is set to the MSEM_IF_WAITERS value and no process is waiting to lock the semaphore, the semaphore will not be unlocked and an error will be returned.

Parameters

Item Description
Sem Points to an msemaphore structure that specifies the semaphore to be unlocked.
Condition Determines whether the msem_unlock subroutine unlocks the semaphore if no other processes are waiting to lock it.

Return Values

When successful, the msem_unlock subroutine returns a value of 0. Otherwise, it returns a value of -1 and sets the errno global variable to indicate the error.

Error Codes

If the msem_unlock subroutine is unsuccessful, the errno global variable is set to one of the following values:

Item Description
EAGAIN Indicates a Condition value of MSEM_IF_WAITERS was specified and there were no waiters.
EINVAL Indicates the Sem parameter points to an msemaphore structure specifying a semaphore that has been removed, or the Condition parameter is not valid.