Re: about NSThread crash
Re: about NSThread crash
- Subject: Re: about NSThread crash
- From: Ken Thomases <email@hidden>
- Date: Wed, 24 Jun 2009 01:28:17 -0500
On Jun 24, 2009, at 1:12 AM, Chris(吴潮江) wrote:
I have some problems when to using thread. As we all know, there is
a method to create a thread,
+ (void)detachNewThreadSelector:(SEL)aSelector toTarget:(id)aTarget
withObject:(id)anArgument.
- (void)aSelector:(id)anArgument
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Here I implement FTP functions. e.g. download/ pause
download/ resume download file.
[pool release];
[NSThread exit];
}
You probably don't need to use a background thread to do FTP. You can
do it using asynchronous methods on the main thread. Since you can,
you probably should. It's almost always less error prone and even
more efficient.
To my surprise, when downloading a file, I pause download and no
error display. Then I resume to download file,
it's ok.
How are you pausing and resuming the download? I assume the user is
controlling this from the GUI. If so, how are you communicating this
request to the background thread? How is the background thread
receiving and acting on the request? When you use multiple threads,
you have to be very careful and deliberate about how you do things
like this. Doing it the "naive" way will get you in trouble.
However, at this time I pause download file, there will be a error
showing EXC_BAD_ACCESS and the stack
information is:
mach_msg_trap
mach_msg
CFRunLoopRunSpecific
CFRunLoopRunInMode
RunCurrentEventLoopInMode
ReceiveNextEventCommon
BlockUnitlNextEventMatchingListInMode
_DPSNextEvent
_[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
_[NSApplication run]
NSApplicationMain
This is the stack for the main thread. Judging from its normality,
it's probably not the thread on which the exception occurred. The
debugger is showing you an arbitrary thread. This can happen if you
rely on Xcode's "auto-attach debugger on crash" feature. You should
launch the program in the debugger, instead -- use Debug instead of
Run. That way, it will reliably show you the proper thread in the
event of a crash.
Regards,
Ken
_______________________________________________
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