• 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: "Charles E. Heizer" <email@hidden>
  • Date: Mon, 23 Feb 2009 12:51:46 -0800

Thanks for the plug. :-) I do appreciate it.

Thanks,
-charles

On Feb 22, 2009, at 9:54 PM, Josh Freeman wrote:

Hi,


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

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.

...

-(void)runSoftwareUpdate
{
	NSTask *task;
   task = [[NSTask alloc] init];
   [task setLaunchPath: @"/usr/sbin/softwareupdate"];

   NSArray *arguments;
   arguments = [NSArray arrayWithObjects: @"-l", nil];
   [task setArguments: arguments];

   NSPipe *pipe;
   pipe = [NSPipe pipe];
   [task setStandardOutput: pipe];

   NSFileHandle *file;
   file = [pipe fileHandleForReading];

   [task launch];

   NSData *data;
   data = [file readDataToEndOfFile];

   NSString *string;
   string = [[NSString alloc] initWithData: data encoding:
NSUTF8StringEncoding];
   NSLog (@"Got a result \n%@", string);
}


   Could the hanging thread be due to the alloc'd NSTask not being
released?


<shameless self-plug>

   You might be interested in checking out the source code to an
open-source app I wrote, DAA Converter; It's a Cocoa wrapper for a
3rd-party command-line tool.

   The sources contain (hopefully helpful) examples for both ways of
using NSTask - asynchronously & synchronously (the latter for when
the task will exit very quickly). There's no explicit use of
NSThread, NSRunLoop, or NSAutoreleasePool, since the NSTasks are
created by the main thread.

   DAA Converter's sources are the bottom of the app's page:
http:// www. twilightedge.com/mac/daaconverter

   The NSTask code is found in DAAC_ConversionTask.m (async begins
in the 'beginDAA2ISOTaskWithDAAFile:ISOFile:' method, sync begins &
ends in the 'daa2isoCredits' method).

Cheers,

Josh



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: 
 >RE: Question on threads running in my Foundation tool (From: Josh Freeman <email@hidden>)

  • Prev by Date: Re: iTunes like transition?
  • Next by Date: RE: Populating a new SQLite Core Data store with default data
  • Previous by thread: RE: Question on threads running in my Foundation tool
  • Next by thread: Re: sdp generating empty header [solved?]
  • Index(es):
    • Date
    • Thread