Re: CPU utilization in Snow Leopard
Re: CPU utilization in Snow Leopard
- Subject: Re: CPU utilization in Snow Leopard
- From: Graham Cox <email@hidden>
- Date: Tue, 20 Oct 2009 17:41:18 +1100
On 20/10/2009, at 5:28 PM, Shashanka L 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.
--Graham
_______________________________________________
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