• 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: waiting for async callback in main thread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: waiting for async callback in main thread


  • Subject: Re: waiting for async callback in main thread
  • From: Jens Alfke <email@hidden>
  • Date: Wed, 28 Oct 2009 10:29:35 -0700


On Oct 27, 2009, at 11:13 PM, John Engelhart wrote:

While Cocoa might do this, there's probably a few "important details" that
you're glossing over. Using a different run loop mode for the the recursive
run of the loop is a good example. I'd be willing to bet there's an
implicit assumption that the tranistion to NSModalPanelRunLoopMode or
NSEventTrackingRunLoopMode "only happens once". In a nutshell, one does not
recursively become modal or recursively begin tracking the mouse, you either
are or you aren't, and it would be an "illegal state transition" to go from
modal to modal.

I've found through experience that the safest thing to do when running a nested runloop like this is to use a unique mode. This prevents unwanted unrelated runloop sources (like incoming UI events) from firing. The tricky part is that you have to ensure that any runloop sources you are waiting on get added to your custom mode. (For example, if waiting on an NSURLConnection, you have to explicitly call its -scheduleInRunLoop:withMode: method.)


The re-entrancy issues aren't going to come up all the time, but they do happen, and can cause really weird behavior that has you scratching your head until you manage to hit a breakpoint and look at your stack realizing you had no idea that this configuration of calls could occur...

—Jens_______________________________________________

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


References: 
 >waiting for async callback in main thread (From: Alexander Cohen <email@hidden>)
 >Re: waiting for async callback in main thread (From: Jens Alfke <email@hidden>)
 >Re: waiting for async callback in main thread (From: Alexander Cohen <email@hidden>)
 >Re: waiting for async callback in main thread (From: Jens Alfke <email@hidden>)
 >Re: waiting for async callback in main thread (From: Alexander Cohen <email@hidden>)
 >Re: waiting for async callback in main thread (From: Jean-Daniel Dupas <email@hidden>)
 >Re: waiting for async callback in main thread (From: John Engelhart <email@hidden>)
 >Re: waiting for async callback in main thread (From: Kyle Sluder <email@hidden>)
 >Re: waiting for async callback in main thread (From: John Engelhart <email@hidden>)

  • Prev by Date: Re: Single Static Library for iPhone and Desktop applications
  • Next by Date: A distinct group of pictures in the bundle
  • Previous by thread: Re: waiting for async callback in main thread
  • Next by thread: Mysterious crash in objc_msgSend in GC app
  • Index(es):
    • Date
    • Thread