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