Re: Help Understanding CFRunLoopSourceSignal and CFRunLoopWakeUp
Re: Help Understanding CFRunLoopSourceSignal and CFRunLoopWakeUp
- Subject: Re: Help Understanding CFRunLoopSourceSignal and CFRunLoopWakeUp
- From: Ken Thomases <email@hidden>
- Date: Tue, 19 Jan 2010 21:53:00 -0600
On Jan 19, 2010, at 9:03 PM, Francisco Tolmasky wrote:
> I have an application that is using a custom CFRunLoopSource (CFRunLoopSourceCreate), however I am not sure about the appropriate way it should be used. Specifically, I don't know whether I am supposed to call CFRunLoopWakeUp after calling CFRunLoopSourceSignal or not. If I get into a situation where there are no other source signaling, will leaving out CFRunLoopWakeUp potentially leave the RunLoop hanging indefinitely (I called runMode:beforeDate:[NSDate distantFuture]). I've tried to find some more in depth documentation beyond Apple's on run loop sources but haven't been able to find much, and nothing that helps me understand the difference (or relationship) between signaling and waking up.
On reviewing the documentation, it seems fairly clear to me. Did you implement a version 0 source? If so, the docs for CFRunLoopWakeUp say:
"Version 0 sources use CFRunLoopWakeUp to cause the run loop to wake up after setting a source to be signaled, if they want the source handled immediately."
The docs for CFRunLoopSourceSignal say:
"After signaling a version 0 source, you need to call CFRunLoopWakeUp on one of the run loops in which the source is registered to get the source handled immediately."
The section about run loops in the Threading Programming Guide says:
"After it hands off its data to the input source, a client must signal the source and wake up its run loop. Signaling the source lets the run loop know that the source is ready to be processed. And because the thread might be asleep when the signal occurs, you should always wake up the run loop explicitly. Failing to do so might result in a delay in processing the input source."
I found all of the above just by using the full-text search in Xcode's documentation window, searching for CFRunLoopWakeUp.
Signaling a version 0 source marks it as having input for the run loop to handle. Waking the run loop lets/makes it handle the sources which are so marked.
CFRunLoopSourceSignal is a function operating on the source. CFRunLoopWakeUp operates on the run loop. They are related, but CFRunLoopSourceSignal won't automatically do anything to any run loop.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden