Documentation
¶
Overview ¶
Package sem provides a way to use System V semaphores.
Index ¶
- Constants
- func Get(key int, nsems int, semflg int) (int, error)
- func GetValue(semid int, semnum int) (int, error)
- func Op(semid int, sops uintptr, nsops int) (bool, error)
- func Operate(semid int, sops []Sembuf) (bool, error)
- func P(semid int, semnum int, semflg int) (bool, error)
- func Remove(semid int) error
- func SetValue(semid int, semnum int, semun int) (bool, error)
- func V(semid int, semnum int, semflg int) (bool, error)
- type Sembuf
Constants ¶
const ( // GETNCNT returns the value of semncnt {READ}. GETNCNT = 14 // GETPID returns the value of sempid {READ} GETPID = 11 // GETVAL returns the value of semval {READ} GETVAL = 12 // GETALL returns semvals into arg.array {READ} GETALL = 13 // GETZCNT returns the value of semzcnt {READ} GETZCNT = 15 // SETVAL sets the value of semval to arg.val {ALTER} SETVAL = 16 // SETALL sets semvals from arg.array {ALTER} SETALL = 17 )
const ( // IPC_CREAT creates if key is nonexistent IPC_CREAT = 01000 // IPC_EXCL fails if key exists. IPC_EXCL = 02000 // IPC_NOWAIT returns error no wait. IPC_NOWAIT = 04000 // IPC_PRIVATE is private key IPC_PRIVATE = 00000 // SEM_UNDO sets up adjust on exit entry SEM_UNDO = 010000 // IPC_RMID removes identifier IPC_RMID = 0 // IPC_SET sets ipc_perm options. IPC_SET = 1 // IPC_STAT gets ipc_perm options. IPC_STAT = 2 )
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get calls the semget system call.
The semget() system call returns the System V semaphore set identifier associated with the argument key.
A new set of nsems semaphores is created if key has the value IPC_PRIVATE or if no existing semaphore set is associated with key and IPC_CREAT is specified in semflg.
If semflg specifies both IPC_CREAT and IPC_EXCL and a semaphore set already exists for key, then semget() fails with errno set to EEXIST.
The argument nsems can be 0 (a don't care) when a semaphore set is not being created. Otherwise, nsems must be greater than 0 and less than or equal to the maximum number of semaphores per semaphore set.
If successful, the return value will be the semaphore set identifier, otherwise, -1 is returned, with errno indicating the error.
func Op ¶
Op calls the semop system call.
semop() performs operations on selected semaphores in the set indi‐ cated by semid. Each of the nsops elements in the array pointed to by sops is a structure that specifies an operation to be performed on a single semaphore. The elements of this structure are of type struct sembuf, containing the following members:
unsigned short sem_num; /* semaphore number */ short sem_op; /* semaphore operation */ short sem_flg; /* operation flags */
Flags recognized in sem_flg are IPC_NOWAIT and SEM_UNDO. If an operation specifies SEM_UNDO, it will be automatically undone when the process terminates.
The set of operations contained in sops is performed in array order, and atomically, that is, the operations are performed either as a complete unit, or not at all. The behavior of the system call if not all operations can be performed immediately depends on the presence of the IPC_NOWAIT flag in the individual sem_flg fields, as noted be‐ low.
func P ¶
P calls the semop P system call. Flags recognized in semflg are IPC_NOWAIT and SEM_UNDO. If an operation specifies SEM_UNDO, it will be automatically undone when the process terminates.