On May 6, 2009, at 8:22 AM, Sparta wrote:
I am working on cocoa – MySQL application that connects to the MySQL
database and retrieves the records.
I run the search in a NSThread. I wish to cancel the search if
needed, as
the searching of the desired data takes 15-20 minutes due to the
bigger size
of database.
Please suggest some method which can cancel / exit the NSThread from
the
parent thread.
Something like this:
....
BOOL stopItMan;
....
- (void) doSomePotentiallyLongWindedStuffOnASecondThread
{
while (!stopItMan) {
.... do some more stuff ....
};
}
- (void) userIsImpatientStopItNow
{
stopItMan = YES;
}
Don't do something like this (which is possible and would require
calling through to some bits of lower level mach or pthread API):
- (void) userIsImpatientStopItNow
{
nukeBackgroundThreadFromSpace();
}
You can't kill a thread arbitrarily as there is no way to know what
state the thread might be in when you kill it unless you do the work
necessary to cause the targeted thread to be blocked at a known safe
point in its execution. However, if the thread is blocked at a known
safe point, that known safe point can just as easily be a test to see
if should continue, exiting safely if not.
b.bum_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com