Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How do you kill a thread in Obj-C?

How do you kill a thread in Obj-C?
Thread Tools
Mac Elite
Join Date: Feb 2001
Location: adrift in a sea of decadent luxury and meaningless sex
Status: Offline
Reply With Quote
Oct 17, 2002, 01:22 AM
 
IIRC, in Java you can get an instance of a thread somehow and send it a kill message (I don't remember how you get the instance, but that's a mystery for another day). Is this possible in Obj-C as well?

if it matters, I have a thread that saves a large file with a function from the QT API, and I can check before and after calling the function to see if the thread has been cancelled, but in order to abort the save operation immediately I'd like to be able to kill the thread from another thread. Is this possible (or dangerous for the disk, or is there a better way)?

thanks
blackmail is such an ugly word. I prefer extortion. the X makes it sound cool
     
Forum Regular
Join Date: May 2001
Status: Offline
Reply With Quote
Oct 20, 2002, 10:54 PM
 
It would be dangerous. Killing a thread gives it no chance to clean up after itself. That is why most API's make doing so very hard
If your computer stops responding for a long time, turn it off and then back on. - Microsoft
     
Mac Elite
Join Date: Feb 2001
Location: adrift in a sea of decadent luxury and meaningless sex
Status: Offline
Reply With Quote
Oct 21, 2002, 01:02 PM
 
yeah, I've read a few other places that it's just not possible in Obj-C. So, is there a way to save a large file in a way that's interuptible? Or can someone give me a short primer on opening a thread in java from my Obj-C project?
blackmail is such an ugly word. I prefer extortion. the X makes it sound cool
     
Professional Poster
Join Date: Sep 1999
Location: Ottawa, ON, Canada
Status: Offline
Reply With Quote
Oct 21, 2002, 02:11 PM
 
Originally posted by lucylawless:
yeah, I've read a few other places that it's just not possible in Obj-C. So, is there a way to save a large file in a way that's interuptible? Or can someone give me a short primer on opening a thread in java from my Obj-C project?
I was under the impression that you could stop a thread, but not kill it. Can you send it the exit message? I haven't programmed threads on Obj-C, so I'm just guessing.
     
Mac Elite
Join Date: Feb 2001
Location: adrift in a sea of decadent luxury and meaningless sex
Status: Offline
Reply With Quote
Oct 21, 2002, 06:13 PM
 
As I understand it, you can send an exit message from within the thread to itself (I think you send the message to the class, actually), but there's not even a way to get an instance of another thread to which to send a message.

Now that I look it up, NSThread only has one instance method (threadDictionary).
blackmail is such an ugly word. I prefer extortion. the X makes it sound cool
     
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status: Offline
Reply With Quote
Oct 22, 2002, 09:49 AM
 
I can't help you with ObjC, but I second the opinion that killing the thread is not a good option. Instead of getting a handle to the thread and sending it a message, get a handle to your object and send that object a message, then the thread executing the instance method on the object will quit.

The issue of interrupting a non-interruptable external library function probably has no easy answer. I would gues that since QT can interrupt saving a large file that there is a way. You are probably using a single function that wraps many other functions for simplicity, so if you can find those you will be set.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:13 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2