 |
 |
How do you kill a thread in Obj-C?
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: adrift in a sea of decadent luxury and meaningless sex
Status:
Offline
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|