Re: Cancel NSThread - cocoa/mysql database search...
On 08 May 09, at 07:08, spartan g wrote: But the problem I am facing now is, once i sent the query to MySQL through SMySQL framework, I am unable to cancel it. This query takes so much time to return the results and cannot be canceled as far as I understand. Is there any way to cancel this query??? any command or API!!! No. The MySQL C API [1] is synchronous, and provides no method to cancel a query that's in progress. Indeed, the network protocol doesn't either - the only way to stop a query that's running is by using the MySQL KILL command to terminate the connection. If you are ending up with queries that run for 15 to 20 minutes, you probably need to do one or more of the following: 1. Adjust your database schema to make these queries run faster 2. Fetch smaller chunks of data at a time using the LIMIT modifier on queries 3. Change your application so that it performs more efficient queries All of these are really outside the scope of Cocoa development, though. You may have better results asking on a MySQL-specific mailing list or forum. [1]: http://dev.mysql.com/doc/refman/5.1/en/c.html ___ 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
Re: Cancel NSThread - cocoa/mysql database search...
Thanks... I tried both the ways as Bill and Mike suggested. I could manage to cancel the thread by checking the bool flag for cancellation. It works fine. But the problem I am facing now is, once i sent the query to MySQL through SMySQL framework, I am unable to cancel it. This query takes so much time to return the results and cannot be canceled as far as I understand. Is there any way to cancel this query??? any command or API!!! Once again Thanks guys... -- Best Regards, Sparta... On Wed, May 6, 2009 at 9:34 PM, Bill Bumgarner wrote: > 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
Re: Cancel NSThread - cocoa/mysql database search...
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
Re: Cancel NSThread - cocoa/mysql database search...
On Wed, May 6, 2009 at 11:22 AM, Sparta 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 (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
Cancel NSThread - cocoa/mysql database search...
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. -- Thanks and Regards, Sparta... ___ 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