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
| Name | Type | Dir | Description |
|---|---|---|---|
| name | const char | - | |
| oflag | int | - | |
| mode | int | - | |
| value | int | - |
Version history
| XNU tag | macOS | # |
|---|---|---|
| xnu-1456.1.26 | macOS 10.6 Snow Leopard | 268 |
| xnu-1699.24.8 | macOS 10.7 Lion | 268 |
| xnu-1486.2.11 | — | 268 |
| xnu-1504.15.3 | — | 268 |
| xnu-1504.3.12 | — | 268 |
| xnu-1504.7.4 | — | 268 |
| xnu-1504.9.17 | — | 268 |
| xnu-1504.9.26 | — | 268 |
| xnu-1504.9.37 | — | 268 |
| xnu-1699.22.73 | — | 268 |
| xnu-1699.22.81 | — | 268 |
| xnu-1699.24.23 | — | 268 |
| xnu-1699.26.8 | — | 268 |
| xnu-1699.32.7 | — | 268 |
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