Skip to Main Content
Condition variables and mutexes are synchronization mechanisms defined in the POSIX Pthreads specification and there are several implementations that address these requirements. Applications wanting to use them for inter-process communication could suffer from process hangs, in the event of unexpected termination of a mutex owning process. Also, if condition waiters need to have fairness associated with them across processes, threads should enable priority scheduling with contention scope set to system level. This could prevent a thread in another process, or in the kernel, from running and lead to starvation. To address these limitations, we present a mechanism to implement FIFO condition wait, signaling and robust mutex using system V semaphores. The paper also describes lockless condition wait, a simple mechanism implemented using compare-and-swap (CAS) atomic primitive. Since semaphores are known to be heavy weight objects, we evaluate the performance of the proposed base implementation in comparison with process shared mutexes and condition variables provided by pthread library on major UNIX platforms. The results indicate that the overheads associated with semaphores even out gradually under heavy loads (with the exception of Native POSIX Thread Library (NPTL) on Linux) on multi-CPU machines lending support to the idea that the implementation could be widely deployed by applications wanting prioritized and robust synchronization.