[Tutor] Killing a thread ..

Remco Gerlich scarblac@pino.selwerd.nl
Wed, 11 Jul 2001 17:44:33 +0200


On  0, Praveen Pathiyil <ppathiyi@cisco.com> wrote:
> Thanks for that pointer. I went through that mail you suggested. But there
> seemed to be a slight difference.
> 
> In my case, the main thread waits for the user input( To press any of the
> buttons). The spawned thread is trying to simulate some real-time message
> processing. So it doesn't seem to be a good idea to ask that thread to check
> a condition variable periodically, because figuratively speaking it just
> want to continue processing and doesn't want to stop. It is the main thread,
> upon "user intervention", that will terminate this "eager-to-continue"
> thread.

As far as I know, that is simply not the way it works. You can't stop a
thread, but the thread can end. It's not that expensive to check a variable
now and then. (I might be wrong on this, but I think I've heard this quite
often).

> Also i can't make the spawned thread to sleep in-between for checking the
> variable.
> 
> I hope that i have somewhat cleared the intent of my usage.
> 
> Just on the same topic, if i am running the function using a  thread object
> (rather just doing a "thread.start_new(func, (..))", will deleting that
> object achieve the effect of killing that thread ? I feel that there is
> something seriously wrong in this, but can someone tell me exactly what :-))
> ?

How would you delete an object? "del ob" will delete the local name 'ob'
that refers to that object, but as long as something else refers to it, the
object will be there (and as long as it's a running thread, there will be
things referring to it).

-- 
Remco Gerlich