• 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: CFRunLoopStop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFRunLoopStop


  • Subject: Re: CFRunLoopStop
  • From: Chris Kane <email@hidden>
  • Date: Sun, 14 Mar 2004 13:15:05 -0800

On Mar 4, 2004, at 11:32 AM, Dave Camp wrote:

On Mar 4, 2004, at 10:36 AM, Dustin Voss wrote:

On 3 Mar, 2004, at 11:00 PM, Todd Lair wrote:

I've been using a secondary RunLoop in a thread, and it has DO NSConnections as well as NSTimers. This loop runs until the thread is ready to exit, and I was able to remove or invalidate those sources which caused the thread's loop to return from the run method call.

Now, I've added an NSURLConnection to the mix, and I'm using this asynchronously. However, I cannot, no matter what I try to do, figure out how to remove the sources it adds so my run loop will end. I've tried, honest.

I'm going to try and use CFRunLoopStop. However, before I give this a shot, I'd like to know that a run loop cleans up its own sources when deconstructred. Once returning from run, I'll be exiting the thread which I assume releases the loop for the thread. Does the runloop deallocate its sources as well when it does this?

I could figure this out, but I've been banging my head on this one for a couple of days, and I have quite a few dents in my head. I thought if someone new, maybe it would save me some extra brain damage.

At least for NSRunLoop, the better way to stop a loop is to run it for a short time, check to see if you should exit, run it for a short time again, etc. As for your question, if the run loop retained its sources, it will release its sources when deallocated.


I've tried CRunLoopStop, and it did not work for me. After some searching in the list archives, Apple's expectations are that you will either use NSRunLoop in a polled fashion (run it for a bit, check your looping variable, repeat...) or just run the runloop and call exit() to terminate the app when you are done. There apparently is no other provisions for escaping from a runloop.

Dave is correct on the way to do this: run the run loop in your own loop with a termination condition of some kind (like, a global variable or per-thread state or some condition you evaluate [like, an array is now empty] or whatever applies in the particular situation). -run is just a convenience with a trivial loop inside it, over one of the other run methods.

Basically, trying to use that exiting semantic is a mistake, because the set of sources other things are adding to a run loop can also change from release to release.

This is a case where the documentation of a behavior has perhaps done more harm than good over the years. The intent of the documenting the behavior isn't to give some information that could be used in a positive or active way (like, remove all the sources that have been added to get the run loop to stop), but rather to warn that there is at least the one condition under which -run might return, and you might want to do something afterwards in the unlikely event that it does.


Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >CFRunLoopStop (From: Todd Lair <email@hidden>)
 >Re: CFRunLoopStop (From: Dustin Voss <email@hidden>)
 >Re: CFRunLoopStop (From: Dave Camp <email@hidden>)

  • Prev by Date: Re: Writing a non-NSDocument based multiple document window apps
  • Next by Date: Re: storing default preferences
  • Previous by thread: Re: CFRunLoopStop
  • Next by thread: Methods returning const char*'s [or similar] - am I responsible for freeing the pointer or not?
  • Index(es):
    • Date
    • Thread