Skip to content
BSD syscall#268

svc · unix #268

sem_open

Opens (or creates) a named POSIX semaphore and returns a sem_t* handle.

Prototype

user_addr_t sem_open(const char *name, int oflag, int mode, int value);

Returns: user_addr_t

Arguments

NameTypeDirDescription
nameconst char-
oflagint-
modeint-
valueint-

Version history

XNU tagmacOS#
xnu-1456.1.26macOS 10.6 Snow Leopard268
xnu-1699.24.8macOS 10.7 Lion268
xnu-1486.2.11268
xnu-1504.15.3268
xnu-1504.3.12268
xnu-1504.7.4268
xnu-1504.9.17268
xnu-1504.9.26268
xnu-1504.9.37268
xnu-1699.22.73268
xnu-1699.22.81268
xnu-1699.24.23268
xnu-1699.26.8268
xnu-1699.32.7268

Examples

C — open with initial count

sem_t *s = sem_open("/job-slot", O_CREAT, 0600, 4);
if (s == SEM_FAILED) perror("sem_open");

Notes

macOS implements named POSIX semaphores on top of Mach semaphores held inside the kernel; the libSystem wrapper keeps a refcounted descriptor table in user space. Unnamed sem_init(2) is intentionally unsupported on Darwin — callers must use sem_open(3) or dispatch_semaphore as an alternative.

Related APIs

sem_closesem_unlinksem_waitsem_postdispatch_semaphore_create