Re: Cancel NSThread - cocoa/mysql database search...
Re: Cancel NSThread - cocoa/mysql database search...
- Subject: Re: Cancel NSThread - cocoa/mysql database search...
- From: Michael Ash <email@hidden>
- Date: Wed, 6 May 2009 11:59:13 -0400
On Wed, May 6, 2009 at 11:22 AM, Sparta <email@hidden> wrote:
> Hi Friends,
>
> 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.
You can't. Thread cancellation is extremely dangerous. You might kill
the thread while it's in the middle of holding an exclusive resource.
That resource would then never be released, which could freeze up your
entire application. As such, NSThread has no way to kill a thread.
The best way to do this is to ask the thread to quit, and have the
thread check periodically. NSThread on 10.5 has a built-in way to do
this, the misleadingly-named -cancel and -isCancelled methods. Check
-isCancelled every so often, and send -cancel when you want the thread
to quit. You may have to redesign your code so that it can check
-isCancelled frequently, though.
Mike
_______________________________________________
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