• 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
Running an NSTask Within an NSThread
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Running an NSTask Within an NSThread


  • Subject: Running an NSTask Within an NSThread
  • From: Jonathan Dann <email@hidden>
  • Date: Sun, 27 Jan 2008 02:09:58 +0000

Hi,

I'm writing an app that needs to run a fairly lengthy background process, but the process itself is an NSTask. Does the task itself run on its own thread anyway or am I better spawning a new thread from my main one? What would be any possible disadvantage? The docs say that a task runs in a separate memory space to the calling app, but I don't know if that's the same thing.

I've tried both ways, and when spawning a thread I have a method that calls [task launch], the method then finished its execution and therefore the thread finishes. I then want to evaluate something when the NSTaskDidFinishNotification is posted (for which my class is an observer). Here's the current catch:

When I don't span a new thread I get NSLogs showing that two calls to my -taskDidFinish:(NSNotification *)note method and a crash. When I spawn a thread, I get no calls to the -taskDidFinsh method, therefore I have a memory leak! Any ideas?

Here's my code

- (void)runTask;
{
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	task = [[NSTask alloc] init];
	// configure task & call some cocoa calls with autoreleased objects

	@try {
	[task launch];
	}
	@catch // blah blah
	}
	[pool release];
}

- (void)taskDidTerminate:(NSNotification *)note;
{
	NSLog(@"-taskDidTerminate:");
	[task release];
	// do more stuff with output of task
}

So think that for some reason I'm getting my task released twice, but I don't know why the taskDidTerminate method is called twice. I don't get this crash when I spawn another thread, could the thread be crashing silently?

Hope this is clear enough, thanks.

Jon
_______________________________________________

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


  • Follow-Ups:
    • Re: Running an NSTask Within an NSThread
      • From: James Bucanek <email@hidden>
  • Prev by Date: Re: Pushing the truth
  • Next by Date: Trying to bind to reverseTransformedValue: in IB
  • Previous by thread: Re: reset NSServices values
  • Next by thread: Re: Running an NSTask Within an NSThread
  • Index(es):
    • Date
    • Thread