• 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: Question on threads running in my Foundation tool
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question on threads running in my Foundation tool


  • Subject: Re: Question on threads running in my Foundation tool
  • From: Ken Thomases <email@hidden>
  • Date: Sun, 22 Feb 2009 12:32:54 -0600

On Feb 22, 2009, at 11:35 AM, Charles E. Heizer wrote:

I reworked my test app so that I could isolate the threads and to see what's going on a little better, and I'm now using a NSTimer and a NSRunLoop. The issue I'm seeing is that for every time I call NSThread so not to block the run loop it runs it's course but when it completes it leaves a hanging thread. So every 60 seconds I see an additional thread get added and never drops it once completed.

You don't need to use a secondary thread to avoid blocking the main thread when you use an NSTask. Just don't use the blocking methods of NSTask or NSFileHandle; use the asynchronous versions.


That is, don't invoke -[NSFileHandle readDataToEndOfFile]. Register for the NSFileHandleReadToEndOfFileCompletionNotification notification and invoke -readToEndOfFileInBackgroundAndNotify. Similarly, don't invoke -[NSTask waitUntilExit]. Register for the NSTaskDidTerminateNotification notification.

If you decide to continue using a secondary thread, try invoking - [NSTask waitUnitExit] after you've read the task's output. I believe that NSTask needs the run loop of the thread from which it is launched to run in order for it to detect the termination of the task, deliver its notification, and perform some housekeeping cleanup. The fact that you're not running the run loop of the thread is the reason it's failing to clean up. The -waitUntilExit method runs the run loop, so it should be sufficient.

Regards,
Ken

_______________________________________________

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: 
 >Question on threads running in my Foundation tool (From: "Charles E. Heizer" <email@hidden>)
 >Re: Question on threads running in my Foundation tool (From: Nick Zitzmann <email@hidden>)
 >Re: Question on threads running in my Foundation tool (From: "Charles E. Heizer" <email@hidden>)
 >Re: Question on threads running in my Foundation tool (From: Nick Zitzmann <email@hidden>)
 >Re: Question on threads running in my Foundation tool (From: "Charles E. Heizer" <email@hidden>)
 >Re: Question on threads running in my Foundation tool (From: Ken Thomases <email@hidden>)
 >Re: Question on threads running in my Foundation tool (From: Michael Vannorsdel <email@hidden>)
 >Re: Question on threads running in my Foundation tool (From: Shawn Erickson <email@hidden>)
 >Re: Question on threads running in my Foundation tool (From: Michael Ash <email@hidden>)
 >RE: Question on threads running in my Foundation tool (From: "Charles E. Heizer" <email@hidden>)

  • Prev by Date: Re: Programmatically opening an NSComboBox list
  • Next by Date: Obtaining Display EDID (DDC) Information From User Level App
  • Previous by thread: RE: Question on threads running in my Foundation tool
  • Next by thread: RE: Question on threads running in my Foundation tool
  • Index(es):
    • Date
    • Thread