Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
cross-process timeoutable semaphores
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

cross-process timeoutable semaphores

I'm trying to port some linux code to OSX, and have the need for a cross-process timeoutable semaphore (semtimedop in particular being in the original code).  This has been extremely frustrating and I'm about two weeks into trying to implement this basic mechanism (that took me about 2 hours to port from win32 to linux originally).
POSIX semaphores won't work because OSX doesn't support sharing them across processes.  Carbon's "multiprocess services" also, strangely, doesn't work across process boundaries.  System V style semaphores are missing the ability to timeout (on OSX) and try+sleep loops won't work because of thread priority inversion.  I actually think I may be close to a working implementation using a mutex-locked homegrown semaphore file and kqueues.....but it seems ridiculously complicated with too much overhead.  I may be missing the boat there anyway if kevent doesn't work exactly like I think it does.  I make one kevent call to start the monitoring, unlock the mutex, allowing the semaphore file to be written, and then make another kevent call to actually start waiting.)  If that first call isn't actually starting the monitoring, I could miss a signal on the semaphore file.  Not to mention spurious wakeups to be dealt with and the like...
I've found a couple open source projects that implement these under OSX, such as Chromium and Firebird, but their implementations assume a scheduling thread or are very complex and rely extensively on a whole suite of supporting code.
My last attempt has been using mach semaphores.  My problem there is poor documentation.  Even after studying mach and its various headers for a couple solid days, I just have no idea how to say to interested processes (which are anonymous, although with significant work I could probably change that) "here's the global port/semaphore name...request the access you need."  I'm really not sure how well it will work since only one task/process can have receive rights on a semaphore/port at the same time anyway.
I haven't looked extensively into Apple Events or these links, which looks like they *might* be helpful, as I'm a little tired spending days following dead-ends:
Is this very basic functionality really this difficult to create, or have I managed to miss a very obvious solution?
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

Visit the Apple Store online or at retail locations.

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.