Re: How to create secondary Thread that listens to event taps?
Re: How to create secondary Thread that listens to event taps?
- Subject: Re: How to create secondary Thread that listens to event taps?
- From: Rainer Brockerhoff <email@hidden>
- Date: Tue, 19 Oct 2010 17:41:30 -0200
At 21:11 +0300 19/10/10, eveningnick eveningnick wrote:
> > You create the secondary thread, install the event tap in it as usual - that is, create a run loop source for the tap and add the source to the current run loop returned by CFRunLoopGetCurrent() - and then, erhm, run the run loop in a loop :-)
>>
>> Something like (warning: typed in Eudora):
>> while (someCondition) {
>> NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
>> SInt32 result = CFRunLoopRunInMode(kCFRunLoopDefaultMode,0.5,YES);
>> [pool drain];
>> if (result==kCFRunLoopRunStopped)) {
>> return;
>> }
>> }
> > should work.
>
>Why did you give 0.5 as the second param of CFRunLoopRunInMode? Is it
>the optimal value?
That means the while(condition) loop cycles every 0.5 seconds, even if nothing happens in the runloop.
A too-low value will make your thread activate too often (making it use more CPU when idle) and a too-high value will make it too slow to react to "condition" being set to NO. I usually set something between 0.5 and 1; it's optimal in the sense "works-for-me" ;-)
--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
Blog: http://brockerhoff.net/blog
_______________________________________________
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