[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Base Operating System and Extensions Technical Reference, Volume 1

msem_init Subroutine

Purpose

Initializes a semaphore in a mapped file or shared memory region.

Library

Standard C Library (libc.a)

Syntax

#include <sys/mman.h>
msemaphore *msem_init (SemInitialValue)
msemaphore *Sem;
int InitialValue;

Description

The msem_init subroutine allocates a new binary semaphore and initializes the state of the new semaphore.

If the value of the InitialValue parameter is MSEM_LOCKED, the new semaphore is initialized in the locked state. If the value of the InitialValue parameter is MSEM_UNLOCKED, the new semaphore is initialized in the unlocked state.

The msemaphore structure is located within a mapped file or shared memory region created by a successful call to the mmap subroutine and having both read and write access.

Whether a semaphore is created in a mapped file or in an anonymous shared memory region, any reference by a process that has mapped the same file or shared region, using an msemaphore structure pointer that resolved to the same file or start of region offset, is taken as a reference to the same semaphore.

Any previous semaphore state stored in the msemaphore structure is ignored and overwritten.

Parameters

Sem Points to an msemaphore structure in which the state of the semaphore is stored.
Initial Value Determines whether the semaphore is locked or unlocked at allocation.

Return Values

When successful, the msem_init subroutine returns a pointer to the initialized msemaphore structure. Otherwise, it returns a null value and sets the errno global variable to indicate the error.

Error Codes

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

EINVAL Indicates the InitialValue parameter is not valid.
ENOMEM Indicates a new semaphore could not be created.

Implementation Specifics

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

Related Information

The mmap subroutine, msem_lock subroutine, msem_remove subroutine, msem_unlock subroutine.

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


[ Previous | Next | Contents | Glossary | Home | Search ]