• 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
NSTask launch from NSThread cause SIGABRT?!?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTask launch from NSThread cause SIGABRT?!?


  • Subject: NSTask launch from NSThread cause SIGABRT?!?
  • From: Allan Odgaard <email@hidden>
  • Date: Thu, 4 Jul 2002 06:32:18 +0200

Hi there,

I have created a dummy class that launches "open /tmp/01.png" using NSThread.

If I call the threadedRun from my normal application then it works fine. If I instead use NSThread to start a new thread (to call the selector) then the program does launch, but my program exits with SIGABRT.

It should be noted that wether or not I get this SIGABRT seems to depend on the command launched -- most commands doesn't have a problem, but "open" does 99% of the time (most likely it has to do with how quickly it detach).

Here's the code I use to launch the thread:

DummyRun *dummy = [[DummyRun alloc] init];
[NSThread detachNewThreadSelector:@selector(threadedRun:) toTarget:dummy withObject:nil];

And here's the DummyRun-class:

@interface DummyRun : NSObject
{
}
- (void)threadedRun:(id)anObject;
@end

@implementation DummyRun

- (void)threadedRun:(id)anObject
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSTask *cmd = [[NSTask alloc] init];
[cmd setArguments:[NSArray arrayWithObjects:@"-c", @"open /tmp/01.png", nil]];
[cmd setCurrentDirectoryPath:[@"~/" stringByExpandingTildeInPath]];
[cmd setEnvironment:[NSDictionary dictionary]];
[cmd setLaunchPath:@"/bin/tcsh"];
[cmd setStandardInput:[NSPipe pipe]];
[cmd setStandardOutput:[NSPipe pipe]];
[cmd setStandardError:[NSPipe pipe]];

[cmd launch];

return;
}

@end

As can be seen, I set *all* properties of NSTask, just so that it doesn't inherit something from my main thread (that would/could cause non-thread-safe stuff), I do not access anything from this selector, only stuff I create in the seleector, and I setup an autorelease pool (which I don't release, but it also fails if I do).

For the records, the NSTask is actually launched (and the command is executed fully).
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Prev by Date: AutoreleasePools and Threads
  • Next by Date: array object creation philosophy
  • Previous by thread: Re: AutoreleasePools and Threads
  • Next by thread: array object creation philosophy
  • Index(es):
    • Date
    • Thread