• 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: CPU utilization in Snow Leopard
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CPU utilization in Snow Leopard


  • Subject: Re: CPU utilization in Snow Leopard
  • From: Joar Wingfors <email@hidden>
  • Date: Tue, 20 Oct 2009 09:00:32 -0700


On 19 okt 2009, at 23.37, Graham Cox wrote:

Since there's no autorelease pool inside your do...while loop, of course it isn't going to get autoreleased then. Autorelease isn't magic, someone has to tell it when it can release - that's you. Put your pool inside the loop so it is created and destroyed each time.


In all fairness, this isn't your responsibility for the most part. For high frequency / long lived loops it typically is though.


On 19 okt 2009, at 23.41, Graham Cox wrote:

-(void)newThread
{
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];


//Some operations...


do //Keeps thread alive till date
{
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow: 0.1]];


} while (mShouldThreadAlive); //Waiting for other process to complete

 [pool release];

}


Mind you, having said what I just said, this is a bad approach anyway. You should not "keep a thread alive" until it gets some flag, that's just wasting CPU time doing nothing but spinning. Instead the thread should sleep until it has something to do. If you need to wait for another thread to finish, use a NSConditionLock to do it properly. Also, if this code is representative, you are spinning it after all the processing has finished, which is pointless. Just let it terminate if it has nothing more to do.


It's unclear what the purpose of the loop at the end of this method is intended to serve. From the code posted here I would agree with Graham that it seems likely that a condition lock is more appropriate.

Do you need a run loop for some reason? Are you using it to communicate with the thread?

j o a r


_______________________________________________

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


References: 
 >Re: CPU utilization in Snow Leopard (From: Shashanka L <email@hidden>)
 >Re: CPU utilization in Snow Leopard (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: Dirty rects getting merged together makes for inefficient drawing
  • Next by Date: Re: CPU utilization in Snow Leopard
  • Previous by thread: Re: CPU utilization in Snow Leopard
  • Next by thread: Re: CPU utilization in Snow Leopard
  • Index(es):
    • Date
    • Thread