• 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
dispatch_sync() lockup workaround
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dispatch_sync() lockup workaround


  • Subject: dispatch_sync() lockup workaround
  • From: Abhi Beckert <email@hidden>
  • Date: Wed, 20 Oct 2010 11:15:55 +1000

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 (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

  • Follow-Ups:
    • Re: dispatch_sync() lockup workaround
      • From: Thomas ClĂ©ment <email@hidden>
    • Re: dispatch_sync() lockup workaround
      • From: Charles Srstka <email@hidden>
  • Prev by Date: Re: MutableArray and TableView Question
  • Next by Date: Re: dispatch_sync() lockup workaround
  • Previous by thread: Re: MutableArray and TableView Question
  • Next by thread: Re: dispatch_sync() lockup workaround
  • Index(es):
    • Date
    • Thread