Hi,

According to the documentation dispatch_sync(dispatch_get_main_queue(), ^{ ... 
}) will lockup if you are already on the main queue.

I have several methods which can be called from either a background queue or 
the main queue, but parts of them *must* be run on the main queue. What is a 
clean workaround for this? I'd like to do something like:

- (void)foo
{
        dispatch_block_t fooBlock = ^{
                NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
                
                /* do stuff */
                
                [pool release];
        };
        
        if (dispatch_get_current_queue() == dispatch_get_main_queue())
                dispatch_exec_block(fooBlock);
        else
                dispatch_sync(dispatch_get_main_queue(), fooBlock);
}

I made up dispatch_exec_block(), it must exist, but I can't find it?

Also, should I be using a higher level API? Perhaps NSBlockOperation? I'm not 
sure how to run an NSBlockOperation on the main queue. And I've noticed 
dispatch_sync() doesn't catch NSExceptions, and I'd really like to have the 
autorelease pool created automatically for me (just to eliminate typo-related 
bugs).

- Abhi_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to