• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: infinite loop in another thread destroy g4 CPU
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
References: 
 >infinite loop in another thread destroy g4 CPU (From: Yorh <email@hidden>)

  • Prev by Date: Re: infinite loop in another thread destroy g4 CPU
  • Next by Date: Re: infinite loop in another thread destroy g4 CPU
  • Previous by thread: Re: infinite loop in another thread destroy g4 CPU
  • Next by thread: Re: infinite loop in another thread destroy g4 CPU
  • Index(es):
    • Date
    • Thread