[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Destroy a thread
- From: William Ahern <william@...>
- Date: Tue, 1 Apr 2014 12:17:23 -0700
On Mon, Mar 31, 2014 at 07:12:30AM -0700, Milind Gupta wrote:
>
> Thanks for your response. So to make the thread garbage collected I
> have to search the lua state's stack and remove the thread object from
> it so that ican get garbage collected?
If the thread is referenced from the stack of the main thread then
presumably it's being used. There shouldn't be any need to search anything.
The only concern is if you have C code that holds a pointer to a lua_State
and there's no other reference anchoring that thread in the VM. Then you
need to manually anchor the thread in the registry to ensure it doesn't get
collected.
> For the environment tables if I don't store them in the global state
> then to access any values from them myself I have to search for the
> thread in the stack, get its environment and then get values from it?
You really shouldn't be in the position of having to search the stack for
anything. The design of your program should include a mechanism to store the
information you need (like a reference to a thread, function, or an
environment table) in the global state somewhere. From C code you usually
use the registry for this.
If you find yourself having to traverse the run-time state in search of some
object, then unless you're writing a debugger or a profiler, you have a
design flaw in your application. You need to arrange to store the
information you need in a well specified manner for later retrieval.