NSRunloop performSelector needs CFRunLoopWakeUp ?
NSRunloop performSelector needs CFRunLoopWakeUp ?
- Subject: NSRunloop performSelector needs CFRunLoopWakeUp ?
- From: David Hoerl <email@hidden>
- Date: Sat, 24 Jan 2009 15:42:26 -0500
I have a few hundred tasks to handle, and am using NSRunLoop's
performSelector to get the scheduled:
-(void)nextTask:(SEL)sel
{
[[NSRunLoop mainRunLoop] performSelector:sel target:self argument:nil order:0
modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];
CFRunLoopRef crf = [[NSRunLoop mainRunLoop] getCFRunLoop];
CFRunLoopWakeUp(crf);
}
One process sends the first message to the worker object. When the
first task is done, "nextTask:" is used to schedule the next one.
Well, it was bizarre - before the CFRunLoopWakeUp addition, only 6 or
7 of the tasks would run, then the process would stall. NSLogs showed
the performSelector message, then nothing.
But, wait, there's more! If I clicked on a window, or clicked on a
menu, then 7 more tasks would run, then another stall. Every click
caused 7 more messages.
In desperation I added the CFRunLoopWakeUp() call; now it runs as I
would expect.
There is an oblique reference to CFRunLoopWakeUp in the Threading
Programming Guide (where documentation on Run Loop Management has
moved), but the usages is for a different purpose (it would seem).
What seems really odd is that I have used this technique in the past
without issue. The current app is single threaded.
Can anyone shed any light on why the CFRunLoopWakeUp() call is
necessary? Is there some other issue I'm missing?
David
PS: Xcode 3.1.2, Leopard 32bit app
PSS: yes, I did google on "NSRunLoop performSelector
CFRunLoopWakeUp", and did find the below note from 2002. However,
there is not mention of this in the Threading Programming Guide. Note
that [NSRunLoop performSelector] results in the creation of a very
short timer:
If you add a timer to the main thread's run loop (which presumably
you've squirreled away somewhere), be sure to use CFRunLoopWakeUp() on
the CFRunLoopRef of the NSRunLoop. Cocoa won't do that for you
currently (and it's not clear it should -- might degrade the performance
unnecessarily).
Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
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