Re: infinite loop in another thread destroy g4 CPU
Re: infinite loop in another thread destroy g4 CPU
- Subject: Re: infinite loop in another thread destroy g4 CPU
- From: Ondra Cada <email@hidden>
- Date: Wed, 5 Apr 2006 11:04:55 +0200
Yorh,
On 5.4.2006, at 9:59, Yorh wrote:
I have a strange problem.
Neither strange nor a problem :)
I made a second thread in my app in this way:
[NSThread detachNewThreadSelector:@selector(checkKeepAlive:)
toTarget:self withObject:nil];
After it i start an infinite loop (as I usually do) like:
-(void)checkKeepAlive:(id)owner{
for (; ; ){
// code
}
}
But the app eat 76% on a G5 CPU and 100% on G4 and about 85% on
Intel core duo....
This is very strange in my thinking because this is a standard
loop... and a lot of apps use this strategy in a secondary thread.
Where is the mistake?
You tell the app to run, so it runs -- using CPU for that. What's
that surprising? :)
If you want it to yield some time even if there are no competitors
(to see idle CPUs and to behave as a good neighbour etc...) add into
your //code something like
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:.1]]
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
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