Re: [RESOLVED] process events in tight loop?
Re: [RESOLVED] process events in tight loop?
- Subject: Re: [RESOLVED] process events in tight loop?
- From: Bill Bumgarner <email@hidden>
- Date: Wed, 13 Jul 2005 23:20:17 -0700
On Jul 13, 2005, at 11:06 PM, Chase wrote:
I should have been more clear. It's already in a second NSThread
and it is not holding up the gui. It just bothers me having it
spinning there like that without any sort of control of its
percentage of processing time compared to that of the main thread.
To remedy this, I have since set the thread priority at the top of
the thread (before entering the loop) to 0.0, and inside the loop
at the bottom I call [NSThread sleepUntilDate:[NSDate
dateWithTimeIntervalSinceNow:0.1]];
I just want it to come up for air every once in a while and also
allow the main thread a bigger piece of the processing pie.
This should work great (and it appears, so far, that the second
thread still has more than enough oomph to do its thing).
Except that your application will never actually idle -- it will
always use CPU cycles even when hidden.
When using a threaded based solution, you should really put some
effort into insuring that the worker thread(s) do not spin. Ever.
Ideally, you should run an NSRunLoop in the thread and post events to
that run loop as your main thread decides co-processing is
necessary. Or, alternatively, events may come in from ports or
sockets (or other things that can be registered in a run loop).
b.bum
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden