On Mar 3, 2009, at 9:17 AM, Nick Rogers wrote:

Hi,
Here's the code:

the following method is running in a separate thread:

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

for (;;)// for loop starts here and is very quick, 100s of iterations per second
        {

                {
                        // this block of code needs to be run at around 1 
second interval
                        // code here
[appController performSelectorOnMainThread:@selector (updateProgress:) withObject:data waitUntilDone:YES];
                }
                // other loop code here
        }
        [loop release];
}

I have tried some crude methods for implementing this running of block of code at 1 second interval but they don't perform as expected, for that I used running a separate thread setting a BOOL var to YES at every 1 second.

Is there a better way to do it?


Calling "+performSelectorOnMainThread" hundreds of times per second would probably not perform very well, since that's a quit heavy weight operation. In this case you probably also wouldn't want to wait on the +performSelectorOnMainThread" to complete before continuing work on the background thread.

An easy and straight forward alternative implementation would be to set a simple "needs update" flag using the atomic operation APIs that you then check periodically from the main thread. The periodic check from the main thread could be done on a repeating timer. You could certainly make it smarter and more fancy, but I think that it would serve as a starting point.

j o a r


_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to