Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ mutex(3x) — HP-UX 9.10

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

shget(2)

shctl(2)

shmat(2)

semget(2)

semctl(2)

semop(2)

msgget(2)

msgctl(2)

msgsnd(2)

msgrcv(2)

 

NAME

Mutex - mutual exclusion class

SYNOPSIS


#include <codelibs/boolean.h>
#include <codelibs/mutex.h>
 class Mutex
{
public:
Mutex(void *base, boolean init = FALSE);
~Mutex();
void destroy();
void read();
void write();
void unlock();
};
 const MUTEX_SHM_SIZE; // size of shared-memory needed by a Mutex
 CC ... -lcodelibs

DESCRIPTION

This class allows the creation of locks in shared memory. 

The constructor takes the base address in shared memory where the shared portion of the Mutex is to be located.  There should only be one Mutex object for a base address within a single process.  The second parameter is optional and if non-zero specifies that the shared portion of the Mutex should be initialized.  The process that creates the shared memory segment should construct its Mutex’s with this parameter set to TRUE.

The amount of shared-memory that a Mutex will need is defined by the const MUTEX_SHM_SIZE.  This macro should be used when allocating the shared-memory segment to ensure that enough room is there for a Mutex.

Once the Mutex is initialized any process that attaches the shared memory segment may attempt to gain a lock with the read or write member functions.  The member function unlock is used to relinquish locks that are gained with read and write.

Since the Mutex lock does not perform any deadlock detection, it is very easy to lock up a program.  The destroy member function should be called to release semaphores and message queues before the last process removes the shared memory segment. 

The basic locking rules for a Mutex are as follows.  One or more processes may have a read lock at the same time.  While a read lock is granted no other process may have a write lock.  Only one process may have a write lock.  While a write lock is granted no other process may have a read lock.  Processes waiting for a write lock will not be blocked indefinitely by new read locks being granted. 

SEE ALSO

shget(2), shctl(2), shmat(2), semget(2), semctl(2), semop(2), msgget(2), msgctl(2), msgsnd(2), msgrcv(2).

  —  

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