sysv_semaphore_array


An os_sysv_semaphore_array is an array of System V semaphores. Unlike most synchronization classes, System V semaphore arrays can be used between processes. These semaphore arrays are primarily used for synchronization of resources shared by multiple processes.

You can create an array of semaphores by constructing an os_sysv_semaphore_array with the number of semaphores as the count. To access the n th semaphore in the array, use semaphore( n ) . By default, any operation that you perform on a semaphore is executed immediately. However, it is sometimes useful to execute a series of operations as a single transaction. To do this, place the semaphore or semaphore array into record mode using record( true ) , which causes the queueing of all operations that obtain, release, or wait for resources. To execute all queued operations in an atomic manner, use execute() . No resources are obtained/released by an execute() until all queued operations succeed. To turn off record mode, use record( false ) .

Conversions permit interchangeable use of os_sysv_semaphore_array and os_vid_t (the System V IPC ID).

Library

Platform<ToolKit> for UNIX

Declaration

#include <ospace/unix/semarray.h>

class os_sysv_semaphore_array

Options

 

Legal open control:

O_OPEN, O_CREAT, O_EXCL

Legal I/O control:

O_NONBLOCK , O_UNDO

Default I/O control:

0

Interface

Constructor
os_sysv_semaphore_array( os_vid_t id )
Constructs an object to reference the existing semaphore array with ID id .
Constructor
os_sysv_semaphore_array( const os_key& key )
Constructs an object to reference the existing semaphore array with key .

Throws: os_unix_toolkit_error

Constructor
os_sysv_semaphore_array( int count , os_mode_t mode )
Constructs an object to reference a new array of count semaphores with a private key and access mode mode .

Throws: os_unix_toolkit_error

Constructor
os_sysv_semaphore_array( const os_key& key , os_open_t open , int count , os_mode_t mode )
Constructs an object to reference a new array of count semaphores with key , open control flags, and mode mode . If a semaphore array with key already exists, references the existing semaphore array and ignores the mode parameter.

Throws: os_unix_toolkit_error

<
bool operator< ( const os_sysv_semaphore_array& array ) const
Returns true if the ID is less than array .
==
bool operator== ( const os_sysv_semaphore_array& array ) const
Returns true if the ID is the same as array .
(os_vid_t)
operator os_vid_t() const
Converts an object to the IPC ID.
clear
void clear()
Flushes any pending operations without executing them.
creator_group
os_gid_t creator_group() const
Returns the creator's group ID.

Throws: os_unix_toolkit_error

creator_user
os_uid_t creator_user() const
Returns the creator's user ID.

Throws: os_unix_toolkit_error

defined
bool defined() const
Returns true if the ID is not OS_UNDEFINED .
execute
void execute()
Atomically executes all operations pending in the queue and clears the queue.

Throws: os_unix_toolkit_error

id
os_vid_t id() const
Returns the IPC ID.
id
void id( os_vid_t id )
Sets the ID to id .
is_legal_index
bool is_legal_index( int index ) const
Returns true if index is a legal semaphore index.

Throws: os_unix_toolkit_error

key
os_key key() const
Returns the key.

Throws: os_unix_toolkit_error

last_change_time
os_time_and_date last_change_time() const
Returns the last time that any of the semaphores changed.

Throws: os_unix_toolkit_error

last_op_time
os_time_and_date last_op_time() const
Returns the last time an operation was performed on any of the semaphores.

Throws: os_unix_toolkit_error

mode
os_mode_t mode() const
Returns the mode.

Throws: os_unix_toolkit_error

mode
void mode( os_mode_t mode )
Sets the mode to mode .

Throws: os_unix_toolkit_error

op
void op( int index , int operation , os_ioctl_t control )
Performs operation on semaphore index with the specified control flags (default blocking and undo ). If the object is in record mode, appends the operation to the pending operations queue; otherwise, performs the operation immediately.

Throws: os_unix_toolkit_error

owner_group
os_gid_t owner_group() const
Returns the owner's group ID.

Throws: os_unix_toolkit_error

owner_group
void owner_group( os_gid_t group )
Sets the owner's group to group .

Throws: os_unix_toolkit_error

owner_user
os_uid_t owner_user() const
Returns the owner's user ID.

Throws: os_unix_toolkit_error

owner_user
void owner_user( os_uid_t user )
Sets the owner's user to user .

Throws: os_unix_toolkit_error

print
void print( ostream& stream ) const
Prints ID and index to stream .
record
bool record() const
Returns true if the object is in record mode.
record
void record( bool flag )
Sets record mode to flag .
remove
void remove()
Immediately removes the semaphore array from the operating system. Any processes still trying to access the semaphores generate errors.

Throws: os_unix_toolkit_error

semaphore
os_sysv_semaphore semaphore( int index )
Returns a semaphore that references the index semaphore.

Throws: os_unix_toolkit_error

semaphore
const os_sysv_semaphore semaphore( int index ) const
Returns a semaphore that references the index semaphore.

Throws: os_unix_toolkit_error

size
size_t size() const
Returns the number of semaphores in the array.

Throws: os_unix_toolkit_error

slot_sequence_number
int slot_sequence_number() const
Returns the slot usage sequence number.

Throws: os_unix_toolkit_error

Non-Member Functions

<<
ostream& operator<<( ostream& stream , const os_sysv_semaphore_array& semarray )
Prints semarray to stream .

Copyright©1994-2026 Recursion Software LLC
All Rights Reserved - For use by licensed users only. - For use by licensed users only.