Inter-Process Communication
System V semaphore
semget
Supported functionality in SCML:
// Creat or open a semaphore set
semget(
    key,
    nsems,
    semflg = IPC_CREAT | IPC_EXCL
);
For more information, see the man page.
semop and semtimedop
Supported functionality in SCML:
struct sembuf = {
    sem_flg = IPC_NOWAIT,
    ..
};
// Semaphore operations without blocking
semop(
    semid,
    sops = [ <sembuf> ],
    nsops
);
Unsupported semaphore flags:
SEM_UNDO
Supported and unsupported functionality of semtimedop are the same as semop.
The SCML rules are omitted for brevity.
For more information, see the man page.
semctl
Supported functionality in SCML:
// Remove the semaphore set
semctl(
    semid,
    semnum,
    cmd = IPC_RMID
);
// Initialize the value of the semnum-th semaphore
semctl(
    semid,
    semnum,
    cmd = SETVAL,
    arg
);
// Return the current value (GETVAL), last operating process's PID (GETPID),
// count of processes awaiting increment (GETNCNT) or count of processes awaiting
// zero (GETZCNT) of the semnum-th semaphore
semctl(
    semid,
    semnum,
    cmd = GETVAL | GETPID | GETNCNT | GETZCNT
);
// Retrieve a copy of the `semid_ds` kernel structure for the specified semaphore set
semctl(
    semid,
    semnum,
    cmd = IPC_STAT,
    arg
);
Unsupported commands:
IPC_INFOSEM_INFOSEM_STATSEM_STAT_ANYGETALLSETALL
For more information, see the man page.
futex
Supported functionality in SCML:
opt_flags = FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME;
// Block current thread if target value at `uaddr` matches `val`, and wait up to `timeout`.
futex(
    uaddr,
    futex_op = FUTEX_WAIT | <opt_flags>,
    val, timeout
);
// Block current thread with bitmask condition if target value at `uaddr` matches `val`,
// and wait up to `timeout`.
futex(
    uaddr,
    futex_op = FUTEX_WAIT_BITSET | <opt_flags>,
    val, timeout, unused = NULL, bitmask
);
// Unblock up to `max_waiters` threads waiting on `uaddr`
futex(
    uaddr,
    futex_op = FUTEX_WAKE | <opt_flags>,
    max_waiters
);
// Unblock up to `max_waiters` threads on `uaddr`, if the value on `uaddr` matches `bitmask`
futex(
    uaddr,
    futex_op = FUTEX_WAKE_BITSET | <opt_flags>,
    max_waiters, unused0 = NULL, unused1 = NULL, bitmask
);
// Unblock up to `max_waiters` threads waiting on `uaddr`, and requeue up to
// `max_requeue_waiters` of the remaining waiters to the target futex at `uaddr2`.
futex(
    uaddr,
    futex_op = FUTEX_REQUEUE | <opt_flags>,
    max_waiters, max_requeue_waiters, uaddr2
);
// Perform atomic operation encoded in `operation` on `uaddr2`. Unblock up to `max_waiters`
// threads waiting on `uaddr`, and conditionally unblock up to `max_waiters2` threads
// waiting on `uaddr2` based on the result of the atomic operation.
futex(
    uaddr,
    futex_op = FUTEX_WAKE_OP | <opt_flags>,
    max_waiters, max_waiters2, uaddr2, operation
);
Unsupported operations:
FUTEX_FDFUTEX_CMP_REQUEUEFUTEX_LOCK_PIFUTEX_UNLOCK_PIFUTEX_TRYLOCK_PI
For more information, see the man page.