Alastair’s Place

Software development, Cocoa, Objective-C, life. Stuff like that.

Cross-process Semaphores With Timeouts on OS X

Someone on darwin-dev recently asked how to go about obtaining a cross-process semaphore that can be waited on with a timeout on OS X.

POSIX semaphores currently don’t support this feature on OS X; nor do System V semaphores. Mach semaphores do support timeouts (see /usr/include/mach/semaphore.h), but it isn’t immediately obvious how to pass one to another process.

Anyway, I thought I’d stick together a simple Mach server to implement named semaphores…


Update 2011-10-14

I’ve moved the code and most of the description to a new page, as that seemed better than leaving it here.