• 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: NSTask, or threading?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTask, or threading?


  • Subject: Re: NSTask, or threading?
  • From: Ken Thomases <email@hidden>
  • Date: Sun, 26 Apr 2009 13:58:24 -0500

On Apr 26, 2009, at 12:39 PM, James Maxwell wrote:

I guess what's not clear to me about NSTask is how to use it for something that *isn't* already a "program" - everything I'm finding about NSTask seems to imply that the task is a separate program (every tutorial seems to be about wrapping command-line apps).

Yes, you have to build a separate executable. You can't make an NSTask to just invoke methods on classes and objects in the main app task.


Making a separate executable isn't all that hard. You can add a Foundation tool target to your project. Add the build product of this new target to the main target, so the executable gets copied into your application bundle. Add your classes to the target. Create a main function that does what the task should do.

Passing data between the background task and the main app task will require some work. Maybe it will be sufficient to use pipes to communicate to/from the background task's standard input/output. Another possibility is Distributed Objects.

The main app has to manage the background task. It has to start it when it's needed, configure it / set it up, and respond appropriately if the task exits/crashes/is killed. It also has to terminate it when appropriate -- if you're communicating with it using pipes, then end- of-file on the background task's standard input is a good way to tell it to terminate. That way, if the main app crashes or otherwise exits without a chance to explicitly clean up, the kernel will still tell the background task to terminate as a side effect of implicit cleanup (i.e. closing all of the main app's file descriptors).

Cheers,
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: 
 >NSTask, or threading? (From: James Maxwell <email@hidden>)

  • Prev by Date: Re: NSTask, or threading?
  • Next by Date: Re: ObjectAlloc and objects that should have been released
  • Previous by thread: Re: NSTask, or threading?
  • Next by thread: Re: NSTask, or threading?
  • Index(es):
    • Date
    • Thread