Re: Threading, save panels, and segfaults
Re: Threading, save panels, and segfaults
- Subject: Re: Threading, save panels, and segfaults
- From: Charles Srstka <email@hidden>
- Date: Sat, 10 Nov 2001 14:48:12 -0600
Argh, so this is a known bug in AppKit... that is going to discourage
people from using threading! I hope this gets fixed. I have a dual
processor machine, and so I rather like threading.
Ah well. I'll do a search for DO and see if it helps. Thanks.
On Saturday, November 10, 2001, at 02:48 PM, Erik M. Buck wrote:
Most of the Application Kit is NOT thread safe. I assume that the
problems
you are having from NSSavePanel in a thread are a symptom of the lake of
thread safety.
The standard way to get around the issues of thread safety is to use
distributed objects to communicate between threads and used the
Application
Kit from only one thread at a time.
See the several previous postings to this forum including working
distributed objects code.
----- Original Message -----
From: "Charles Srstka" <email@hidden>
To: <email@hidden>
Sent: Friday, November 09, 2001 11:57 PM
Subject: Threading, save panels, and segfaults
I have had a non-reproducible periodic crash that is driving me nuts.
Using NSLogs, I have traced it to a line of code that is
straightforward
enough that I can't imagine how it could cause a segfault, but it
does...
Here's the code where the crash occurs:
- (void)<the name of this particular method>
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSSavePanel *sp;
int answer;
NSNumber *i;
NSEnumerator *fileEnum = [outlineView selectedRowEnumerator];
<various other variable declarations>
while (i = [fileEnum nextObject])
{
PackageItem *fileToSave = [outlineView itemAtRow:[i
intValue]];
NSString *pathToExtract = [fileToSave filename];
NSLog(@"pathToExtract is %@\n",pathToExtract);
// the previous line works, so I know that pathToExtract is
good
and
// isn't causing the problem
NSLog(@"Before save panel\n");
sp = [NSSavePanel savePanel];
NSLog(@"Before run modal\n");
// the next line is where it crashes!
answer = [sp runModalForDirectory:NSHomeDirectory()
file:pathToExtract];
NSLog(@"After run modal\n");
<more stuff, not relevant to this>
Some notes:
The crash is sporadic and only occurs once in a while. Therefore, I
can't reproduce it.
It may be relevant that this method is being run in a new thread,
using:
[NSThread detachNewThreadSelector:@selector(<the method name>)
toTarget:<the object the method is in> withObject:nil];
I don't understand how threading this could cause a segfault when
opening a save panel, but then, I'm a newbie and could be missing
something. I do like the program being multi-threaded, though, so if
there's a way to keep the threading while eliminating the crash, I
would
like to know how to do it.
One other thing that may be relevant is that every once in a while I
get
error messages at the console of the following type:
*** _NSAutoreleaseNoPool(): Object <some hex number> of class <insert
one of the following: NSCFString, NSPathStore2, NSCalibratedRGBColor,
NSConcreteAttributedString> autoreleased with no pool in place - just
leaking
I find this odd since I'm using an NSAutoreleasePool in every method
that I'm spawning in a new thread. Also, some of the objects that are
leaking (such as NSCalibratedRGBColor) seem like objects that UI
elements would use, definitely not anything I'm using directly.
Please forgive me if this question has been asked before or has an
obvious answer. I would be very appreciative if anyone has any insights
as to why this could be occurring.
Thanks,
Charles Srstka
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev