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

Re: cross-process timeoutable semaphores



I had a lot of strange buggy behavior when I tried the SIGALRM approach. I didn't spend too much time digging into it with gdb or anything because the time precision (1 second intervals) might not be adequate for the performance needs of the application anyway. Also, this approach has been suggested for this problem elsewhere, and I've never seen a "that worked" response, so I'm not sure about it. If anyone has tried it and had it work, I'd love to hear it.

I've thought about a similar tact where I spawn another thread to perform the blocking call on the semaphore, and then use timeoutable pthread synchs between it and the main thread, but given the app's semaphore use, I'm really not sure how many hung threads the task might end up with. Maybe acceptable, I guess, but ridiculously complicated and certainly far from optimal, especially later for anyone else trying to debug a threading issue or the like...

Obviously, there's probably solutions that don't require this semaphore for the application as a whole and are more optimal. Unfortunately, I'm working in an OS abstraction layer and modifying all the code outside of it to work with some other mechanism just isn't feasible in the time I have...which I've used half of just trying to solve this one problem.

Regarding this:
<email@hidden>
From what I understand, you should be able to pass a mach semaphore over a mach port to the other process and then use semaphore_timedwait.


The structure of the mach semaphore itself, which is actually a mach port right, is not valid across a task/process boundary (KERN_INVALID_NAME). Mach mechanisms seem to exist for passing port rights to another task. I guess what I need is the ability to put those port rights in named storage, probably a port, so any other task that knows the name can pick them up. If anybody more familiar with mach than me could provide any guidance, I'd certainly be appreciative, but I basically don't know mach well enough to implement cross-process semaphores in it myself. There's an open source project called Firebird that may have had luck with this approach, but I can't make heads or tails of their newest semaphore code for OSX.



----- Original Message ----- From: "Stephen J. Butler" <email@hidden>
To: "Darwin Dev" <email@hidden>
Sent: Wednesday, November 11, 2009 4:50 PM
Subject: Re: cross-process timeoutable semaphores



On Wed, Nov 11, 2009 at 4:18 PM, Tyler Sample <email@hidden> wrote:
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)

Untested theory: can you use alarm/setitimer with SysV style semaphores? I believe SIGALRM is a synchronous signal, so would be delivered on the thread you set it on. Then you'd check your sem calls for EINTR. _______________________________________________ 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

_______________________________________________
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


References: 
 >cross-process timeoutable semaphores (From: "Tyler Sample" <email@hidden>)
 >Re: cross-process timeoutable semaphores (From: "Stephen J. Butler" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.