• 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
How to exit a thread help...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to exit a thread help...


  • Subject: How to exit a thread help...
  • From: Tom Jones <email@hidden>
  • Date: Sat, 25 Oct 2008 11:00:12 -0700

Hello,
I'm writing a Foundation tool and I need to run a NSTask in a separate thread. I have it working but when the task completes the thread is still running. I tried issuing a [NSThread exit] but that did nothing.


What am I missing?

Thanks,
tom


This my main code

#import <Foundation/Foundation.h>
#import "Threader.h"
#import "RunTask.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	Threader *oo = [[Threader alloc] init]; //Second Thread
	RunTask *newRunTask = [[RunTask alloc] init]; // Thrid Thread

// Start second thread
[NSThread detachNewThreadSelector:@selector(entryPoint:) toTarget:oo
withObject:[NSArray arrayWithObjects:@"SecondThread",@"10",nil]];

[NSThread detachNewThreadSelector:@selector(runSysProfiler:) toTarget:newRunTask withObject:nil];

for (;;) {
NSLog(@"Main Thread is running...");
sleep(5);
}

[pool drain];
return 0;
}


@implementation RunTask

-(void) runSysProfiler:(id *)obj {

NSAutoreleasePool *newpool = [[NSAutoreleasePool alloc] init];

NSLog(@"System Profiler Started, going to delay 10 seconds");
[NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:10]];
NSLog(@"Thread delay done.");

NSTask *sysProfiler = [[NSTask alloc] init];
[swUpdate setLaunchPath:@"/usr/sbin/system_profiler"];
[swUpdate setArguments:[NSArray arrayWithObjects:@"SPHardwareDataType",nil]];

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

NSFileHandle *file;
file = [pipe fileHandleForReading];

[sysProfiler launch];

NSData *data;
data = [file readDataToEndOfFile];

NSString *string;
string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];


	NSLog (@"Hey, we got it...\n%@", string);
	[newpool release];
}

@end
_______________________________________________

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: How to exit a thread help...
      • From: Ken Thomases <email@hidden>
  • Prev by Date: Re: Rotation in CAAnimation layers
  • Next by Date: Re: Controlling Preference Panel Installation
  • Previous by thread: Re: Creating icons and other resources
  • Next by thread: Re: How to exit a thread help...
  • Index(es):
    • Date
    • Thread