Friday, December 7, 2007

Semaphores With Timeouts

Firebird normally makes use of semaphores with timeouts, and I read on an Apple mailing list the following question posted in May 2004:

I have a project that depends on semaphores with timeouts (sometimes
referred to as realtime extensions to semaphores). I use autoconf to
select either SysV semaphores or POSIX semaphores, but MacOS X does not
have a complete set of either one. Neither sem_timedwait nor semtimedop
are implemented. On top of that, the POSIX semaphore implementation
doesn't even have sem_init (though I did see the recent discussion about
it on this list, so I'm moderately hopeful for 10.4).
Are semtimedop or sem_timedwait implementations planned anytime soon?"

Well he answer is no. Leopard MacOS 10.5 doesn't solve the problem either. Hence a number of changes we have had to make to the Firebird code and build process to handle this. Look at the latest (being committed) and semaphore.h to see how we have had to try and work around what should not be a problem by using a poor man's semaphore based on a mutex and conditional variable.

Hint to the Apple developers - You really should fix this soon.


Tom said...

I know it's not exactly the same, but you can use mach semaphores (/usr/include/mach/semaphore.h). It's fairly easy to write a C macro wrapper to decide between sem_init/semaphore_create, sem_wait/semaphore_wait and sem_post/semaphore_signal. It also has timeouts which I think you were wanting. Feel free to email me if you have any questions about semaphores.

Roger Pack said... appears related