• 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: unable to break out of runloop because timers are fired and then the loop waits
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unable to break out of runloop because timers are fired and then the loop waits


  • Subject: Re: unable to break out of runloop because timers are fired and then the loop waits
  • From: Jason Coco <email@hidden>
  • Date: Wed, 24 Sep 2008 17:44:45 -0400


On Sep 24, 2008, at 15:15 , Jason Bobier wrote:

Hey folks, I have a runloop on a thread that looks like this:

while (! _cancelled) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

[runloop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
[pool release];
}


And I put a timer in the loop that sets _cancelled to true, the runloop never stops. What's the proper way to do this?

The run loop only returns from this call when one of the following happens: 1) it has no input sources or timers left; 2) the
beforeDate: date expires; or 3) an input source has been triggered and processed.


Timers don't count as input sources, they are handled at a different part of the event loop. Also, even if you haven't added
any timers or input sources to the run loop, many of the high-level frameworks (like AppKit) do, so you can't be sure that
the call will return just because you haven't put anything.


Your options, then, are to use a shorter date, as was suggested, or to have an actual input source that gets triggered (the Mach Port Poke), also
suggested already. I just wanted to let you know why this happens :)


HTH, J

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: 
 >unable to break out of runloop because timers are fired and then the loop waits (From: Jason Bobier <email@hidden>)

  • Prev by Date: Re: Unable to launch about panel for the 2nd time
  • Next by Date: Re: setPrimitiveValue:forKey: and to-many relationships
  • Previous by thread: Re: unable to break out of runloop because timers are fired and then the loop waits
  • Next by thread: Re: unable to break out of runloop because timers are fired and then the loop waits
  • Index(es):
    • Date
    • Thread