• 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
Re: dispatch_sync(dispatch_get_main_queue() UI weirdness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dispatch_sync(dispatch_get_main_queue() UI weirdness


  • Subject: Re: dispatch_sync(dispatch_get_main_queue() UI weirdness
  • From: Quincey Morris <email@hidden>
  • Date: Fri, 05 Sep 2014 20:48:52 +0000

On Sep 5, 2014, at 13:31 , Jonathan Guy <email@hidden> wrote:

> The callback is basically structured like this
>
> 	__block BOOL accept;
>
> 	if ([NSThread isMainThread]) {
> 		accept = [[Controller sharedController] shouldIAccept:certInfo];
> 	}
> 	else {
> 		dispatch_sync(dispatch_get_main_queue(), ^{
> 			accept = [[Controller sharedController] shouldIAccept:certInfo];
> 			// This is where UI starts playing up when the controller shows the cert
> 		});
> 	}
>
> 	return accept;
>
> So the shouldIAccept method needs to block hence runModal. I also just threw the window up and created my own modal loop but same problem.

It seems to me you’re *still* abusing the main thread. A dispatch_sync blocks the main thread, so it can’t be allowed to do anything that run asynchronously on the main thread (such as displaying a dialog) since that won’t complete.

I suggest you approach this by denying yourself the use of dispatch_sync. I don’t know if Jens will have a better approach, but I’d be inclined to do it with a semaphore (dispatch_semaphore_t) protecting the ‘accept’ variable, and a dispatch_async to the main queue to ask the user what to do. GCD semaphores are incredibly easy to use.

_______________________________________________

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(dispatch_get_main_queue() UI weirdness
      • From: Jens Alfke <email@hidden>
References: 
 >dispatch_sync(dispatch_get_main_queue() UI weirdness (From: Jonathan Guy <email@hidden>)
 >Re: dispatch_sync(dispatch_get_main_queue() UI weirdness (From: Jens Alfke <email@hidden>)
 >Re: dispatch_sync(dispatch_get_main_queue() UI weirdness (From: Jonathan Guy <email@hidden>)

  • Prev by Date: Re: dispatch_sync(dispatch_get_main_queue() UI weirdness
  • Next by Date: Re: dispatch_sync(dispatch_get_main_queue() UI weirdness
  • Previous by thread: Re: dispatch_sync(dispatch_get_main_queue() UI weirdness
  • Next by thread: Re: dispatch_sync(dispatch_get_main_queue() UI weirdness
  • Index(es):
    • Date
    • Thread