• 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
Re: Cancel NSThread - cocoa/mysql database search...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Cancel NSThread - cocoa/mysql database search... (From: Sparta <email@hidden>)

  • Prev by Date: Re: NSNotificationQueue & NSOperationQueue thread death
  • Next by Date: Re: NSNotificationQueue & NSOperationQueue thread death
  • Previous by thread: Cancel NSThread - cocoa/mysql database search...
  • Next by thread: Re: Cancel NSThread - cocoa/mysql database search...
  • Index(es):
    • Date
    • Thread