Pipe-Sem 1.0

Pipe-Sem - Pollable Semaphores implementation for Unix systems.
Pipe-Sem - Pollable Semaphores implementation for Unix systems.

When developing ASYNC applications, I often had the need for locking primitives that could be fed inside a pollable device like select, poll or epoll. Many syncronization primitives are available for Unix systems, but any of them expose a pollable interface to the user. In these cases, if the caller execute a down operation on a blocking semaphore, the application will sleep and whole ASYNC loop will starve because of the wait. To cope with this problem in my ASYNC software, I developed a pipe based semaphore implementation, that I called Pipe-Sem.

The implementation is trivially simple and it uses the pipe internal mechanisms to expose a pollable wait interface. Besides the standard semaphore operations, the function psem_down_fd() can be used to retrieve a files descriptor that can be dropped inside a Unix pollable API like select(2), poll(2) or epoll(2). The caller will have to wait for input events (POLLIN), and when receiving the event itself, the caller should invoke the psem_try_down() function to try to acquire the semaphore. Note that receiving an event from the pollable interface, does not mean that we acquired to semaphore, and the function psem_try_down() will have to be called (and tested for zero return code) to correctly complete the down operation

last updated on:
April 8th, 2008, 10:36 GMT
license type:
GPL (GNU General Public License) 
developed by:
Davide Libenzi
ROOT \ Utilities
Download Button

In a hurry? Add it to your Download Basket!

user rating 16



Rate it!

Add your review!