Re: Termination of threads.
Re: Termination of threads.
- Subject: Re: Termination of threads.
- From: email@hidden
- Date: Fri, 8 Feb 2002 18:37:57 -0500
On Friday, February 8, 2002, at 02:08 PM, email@hidden wrote:
Hello, everybody.
I want to be able to terminate Threads within my application. Cocoa
seems to define only one function that will be able to do what I want,
namely the [NSThread exit]. However, while looking at the docs I saw
the plus. Ooops. Things seem more complicated than that...
As far as I get it, I need to set up a proxy object from the callee
thread (my UI interface) to the thread that has to be terminated.
Then, I invoke a function through the proxy and the thread receives
the message and terminates itself.
Question 1: Will this work?
Question 2: Is there a better/quicker/more elegant way of doing this?
I hate Cocoa's complicated inter-thread communication system.
Thank you very much for any input.
Nick
Yup, that's basically the way to do it.
I can say that for something like this, a full DO implementation isn't
needed. If you already have that, then that's fine, use it. But if you
need to fire off a thread to do come computation and don't need it to
update the UI directly, then not using DO works just as well (you'd
just use NSLocks to synchronize).
The problem with calling +exit (or if there was one -exit) is that
those calls stop the thread right then and there. No cleanup, nothing
else is called - so if you have resources allocated, they just got
leaked. Pthreads has pthread_cancel/pthread_testcancel which helps with
this, but there are still issues with system calls that can be
cancelled, etc. In my threads programming, I've found it easier and
less complicated to have my own cancel/abort/stop strategy worked out
specific to that thread and what it's doing.
True, there can be leaking and cleanup. What is the problem of attaching
a delegate method to a thread that will do the cleanup for the thread?
Mike
----
Mike Shields <mailto:email@hidden>
CD Monkey
Apple Computer, Inc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.