[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
Base Operating System and Extensions Technical Reference, Volume 1

msem_unlock Subroutine

Purpose

Unlocks a semaphore.

Library

Standard C Library (libc.a)

Syntax

#include <sys/mman.h>
int msem_unlock (SemCondition)
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

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:

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.

Implementation Specifics

The msem_unlock subroutine is part of Base Operating System (BOS) Runtime.

Related Information

The msem_init subroutine, msem_lock subroutine, msem_remove subroutine.

List of Memory Mapping Services and Understanding Memory Mapping in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]