#11208: POSIX semaphores have incorrect sharing semantics --------------------------+------------------------------ Reporter: hamish | Owner: nobody Type: bug | Status: new Priority: normal | Milestone: R1 Component: System/POSIX | Version: R1/Development Keywords: | Blocked By: Blocking: | Has a Patch: 0 Platform: All | --------------------------+------------------------------ POSIX semaphores should only be shared between processes if a non-zero pshared value is given to `sem_init`, and the semaphore resides in a shared region of memory (like a `PTHREAD_PROCESS_SHARED` mutex). The POSIX spec is not explicit about it, but this is how Linux and FreeBSD behave. Haiku ignores the latter requirement, so pshared semaphores in private memory (e.g. the stack or heap) are shared after a fork. Test case: {{{ #include <semaphore.h> #include <unistd.h> #include <assert.h> #include <stdio.h> int main() { sem_t sem; int res = sem_init(&sem, 1, 0); assert(res == 0); int pid = fork(); assert(pid != -1); if (pid == 0) { res = sem_post(&sem); assert(res == 0); } else { res = sem_wait(&sem); assert(res == 0); } printf("End\n"); return 0; } }}} The parent process should wait indefinitely on the semaphore, but it does not. -- Ticket URL: <https://dev.haiku-os.org/ticket/11208> Haiku <https://dev.haiku-os.org> Haiku - the operating system.