Pipe-Sem 1.0

Pipe-Sem - Pollable Semaphores implementation for Unix systems.

  Add it to your Download Basket!

 Add it to your Watch List!


Rate it!
send us
an update
GPL (GNU General Public License) 
3.1/5 16
Davide Libenzi
ROOT \ Utilities
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

#Pollable Semaphores #Semaphores implementation #UNIX utility #Pollable #Semaphores #implementation #pipe

Add your review!