Page 1 of 1

Removing Threads

Posted: Mon Jul 22, 2013 3:01 pm
by Eversome
Hey, I was just wondering if there was some way to remove a thread after it finishes. I want to do this because:

(a.) Two threads can't have the same name. Unusable threads are a waste of space.
(b.) I can't use thread:start() to restart the thread until 0.9.0 ):
(c.) I hate the finished thread's guts and I want it to burn in a firey death.

Re: Removing Threads

Posted: Mon Jul 22, 2013 3:10 pm
by bartbes
You need to wait on it for it to get cleaned up.

Re: Removing Threads

Posted: Mon Jul 22, 2013 3:12 pm
by Eversome
bartbes wrote:You need to wait on it for it to get cleaned up.
Alright, thanks for clearing that up. It wasn't exactly clear in the wiki ^^

Re: Removing Threads

Posted: Mon Jul 22, 2013 3:19 pm
by T-Bone
I guess garbage collection takes care of it? In that case, you have to make sure you don't have any references to it, just like any other object.

Re: Removing Threads

Posted: Mon Jul 22, 2013 4:13 pm
by Eversome
It seems that if I call :wait() on the finished thread and then :start() directly after, it restarts the thread rather than cleaning it up. Is this intended behavior?

Re: Removing Threads

Posted: Mon Jul 22, 2013 4:30 pm
by raidho36
Well, you kept the reference, so how did you expected thread to get cleaned?

Re: Removing Threads

Posted: Mon Jul 22, 2013 5:36 pm
by Eversome
Hmm. If I use return at the bottom of a thread, does it empty the thread's message pool?

Re: Removing Threads

Posted: Mon Jul 22, 2013 9:49 pm
by raidho36
To get rid of reference? Erm, no.

Code: Select all

mythread = nil

Re: Removing Threads

Posted: Mon Jul 22, 2013 10:19 pm
by bartbes
Eversome wrote:Hmm. If I use return at the bottom of a thread, does it empty the thread's message pool?
It doesn't. There's an implicit return anyway. That said, when the thread object is garbage collected, then it will destroy the messages with it.