Re: dispatch_sync() lockup workaround
Re: dispatch_sync() lockup workaround
- Subject: Re: dispatch_sync() lockup workaround
- From: Charles Srstka <email@hidden>
- Date: Tue, 19 Oct 2010 20:55:18 -0500
On Oct 19, 2010, at 8:15 PM, Abhi Beckert wrote:
> 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?
fooBlock()?
Charles_______________________________________________
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