This repository was archived by the owner on Nov 9, 2022. It is now read-only.
Tags: microsoft/ftl-sdk
Tags
Fix semaphore implementation on non-Android Unix. (#67) The current implementation uses sem_open(), which creates semaphores in a global system namespace; if the caller asks for a process-private semaphore, it appends a random number to the name to avoid collisions. Unlike on Windows, these semaphores are not destroyed when the last handle is closed; they stay around until someone explicitly calls sem_unlink(). Unfortunately, 10A37 this means that if the hosting app crashes, it'll leak semaphores until the system reboots. On Android, the code uses sem_init() instead. This is another standard POSIX function, which has the capability to create true process-private semaphores, but is not implemented on some platforms, such as macOS where it just returns ENOSYS - presumably the reason the code path is limited to Android. As an entirely separate issue, on macOS, POSIX semaphore names are limited to only 31 characters. One of the semaphores created is named "/ConnectionThreadShutdown", which is 25 characters by itself; after adding an underscore and a random number, it'll only fit if the random number happens to be <= 99999! This commit abandons POSIX semaphores entirely in favor of emulating process-private semaphores using pthread condition variables. This avoids the leak issue and should also be faster. As for global semaphores, well - nothing in the FTL SDK actually uses them, so I decided to just remove the is_global argument from os_semaphore_create() and only support process-private semaphores.
PreviousNext