semop(2)
_________________________________________________________________
semop System Call
Semaphore operations.
_________________________________________________________________
SYNTAX
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
int semop (id, user_ops, nsops)
int id;
struct sembuf *user_ops;
unsigned nsops;
PARAMETERS
id A semaphore set identifier.
user_ops An array of semaphore operations to perform.
nsops The number of semaphore operation records in
<user_ops>.
DESCRIPTION
Semop atomically performs <nsops> semaphore operations on the
semaphore set identified by <id>. The semaphore operation
records are located in the array given by <user_ops>.
A semaphore operation has three components: a semaphore number
(sem_num), a semaphore operation (sem_op), and an operation
modifier (sem_flg). A semaphore operation is performed by
applying the operation, sem_op, modified by sem_flg, to the
semaphore specified by sem_num in the semaphore set identified by
<id>. Sem_op specifies one of three semaphore operations as
follows:
* sem_op < 0: Perform_a_P_operation
If the semaphore's value is greater than or equal to the absolute
value of sem_op, the operation is successful. In this case, the
absolute value of sem_op is subtracted from the semaphore's
value, and, if the SEM_UNDO bit of sem_flg is set, the absolute
value of sem_op is added to the calling process's semaphore
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
semop(2)
adjustment value for the semaphore.
If the semaphore's value is less than the absolute value of
sem_op and the IPC_NOWAIT bit of sem_flg is set, semop will
return with the error condition EAGAIN.
If the semaphore's value is less than the absolute value of
sem_op and the IPC_NOWAIT bit of sem_flg is clear, semop will
suspend the calling process until:
* the semaphore's value becomes greater than or equal to the
absolute value of sem_op, in which case, the operation is
retried,
* <id> is removed from the system, in which case, semop will
return with the error condition EIDRM, or
* the calling process receives a signal that is to be caught,
in which case, semop will return with the error condition
EINTR.
* sem_op > 0: Perform_a_V_operation
The value of sem_op is added to the semaphore's value and, if the
SEM_UNDO bit of sem_flg is set, the value of sem_op is subtracted
from the calling process's semaphore adjustment value for the
semaphore.
* sem_op == 0: Wait_for_zero
If the semaphore's value is zero, the operation is successful.
If the semaphore's value is non-zero and the IPC_NOWAIT bit of
sem_flag is set, semop will return with the error condition
EAGAIN.
If the semaphore's value is non-zero and the IPC_NOWAIT bit of
sem_flg is clear, semop will suspend the calling process until:
* the semaphore's value becomes zero or equal to the absolute
value of sem_op, in which case, the operation is retried,
* <id> is removed from the system, in which case, semop will
return with the error condition EIDRM, or
* the calling process receives a signal that is to be caught,
in which case, semop will return with the error condition
EINTR.
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)
semop(2)
The operation performed by semop is the composition of the
individual operations given by <user_ops>. This composition is
subject to the following:
* Semop performs the composite operation atomically. Semop
succeeds and changes all subject semaphores only when all
individual operations can be performed at a given time.
* The individual operations are performed in the order given
by <user_ops>.
* The calling process is suspended due to the first individual
operation in <user_ops> that requires suspension.
* When the calling process is suspended, it is registered as
waiting for only one semaphore's value to either increase or
become zero, that semaphore being the subject semaphore of
the individual operation that suspended the process.
* Neither the individual operations nor the composite
operation are guaranteed to solve the mutual exclusion
livelock problem.
If semop fails, the semaphore set will remain unchanged. Upon
successful completion, the calling process is recorded as the
last process to perform an operation on each semaphore specified
in the array pointed to by <user_ops> and the current time is
recorded as the most recent time a semop operation was performed.
ACCESS CONTROL
Alter access to the semaphore set is required to change the value
of a semaphore. Read access is required to wait for a semaphore
value to become zero.
RETURN VALUE
0 Completed successfully.
-1 An error occurred. Errno is set to indicate the
error.
EXCEPTIONS
Errno may be set to one of the following error codes:
DG/UX 4.00 Page 3
Licensed material--property of copyright holder(s)
semop(2)
EINVAL <Semaphore_set> is not a valid semaphore set
identifier.
EINVAL The number of semaphores for which the calling
process requests a SEM_UNDO would exceed the
system-imposed limit.
EFBIG Sem_num is less than zero or greater than or equal
to the number of semaphores in the set associated
with <id> for one or more semaphore operations.
E2BIG <nsops> is greater than the system-imposed
maximum.
EACCES One of the semaphore operations (sem_op) is non-
zero and the caller does not have write access.
EACCES One of the semaphore operations (sem_op) is zero
and the caller does not have read access.
EFAULT <user_ops> is an illegal address.
EAGAIN Semaphore operations would result in suspension of
the caller who has requested IPC_NOWAIT
ENOSPC The limit on the number of processes requesting a
SEM_UNDO would be exceeded.
ERANGE One of the semaphore operations would cause a
semaphore's value to overflow the system-imposed
limit.
ERANGE One of the semaphore operations would cause a
process's semaphore adjustment value to overflow
the system-imposed limit.
EIDRM <id> was removed from the system while the caller
was suspended by semop.
DG/UX 4.00 Page 4
Licensed material--property of copyright holder(s)
semop(2)
EINTR The caller received a signal that was set to be
caught while suspended by semop.
SEE ALSO
The related system calls: exec, exit, fork, semctl, semget.
The related manual section: intro(2).
DG/UX 4.00 Page 5
Licensed material--property of copyright holder(s)