Pipe-Sem is a Unix-compatible software tool that implements pollable semaphores to support inter process communication. It allows processes to communicate their readiness for work, rather than continually polling for updates.
To address this issue in my ASYNC software, I developed a pipe-based semaphore implementation called Pipe-Sem. The implementation is simple and utilizes the pipe internal mechanisms to expose a pollable wait interface. In addition to standard semaphore operations, the function psem_down_fd() retrieves a file descriptor that can be dropped into a Unix pollable API like select, poll, or epoll. The caller then waits for input events (POLLIN) and invokes the psem_try_down() function when receiving the event itself to try and acquire the semaphore.
It is important to note that receiving an event from the pollable interface does not mean that the semaphore has been acquired. The caller must still call psem_try_down() and test for a zero return code to complete the down operation correctly. Overall, Pipe-Sem is an effective solution for managing pollable semaphores in ASYNC applications on Unix systems.
Version 1.0: N/A