lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


hello everyone:

     When i use lua_newthread to create a lua thread,i will got a lua_State pointer.
     from manual, it is said:"There is no explicit function to close or to destroy a thread. Threads are subject to garbage collection, like any Lua object".
     Problem is:I kept a lua_State pointer (for the newly created thread) outside the VM,and I have no way to tell VM when i don't need it.if the thread been sweeped as garbage,does the pointer i kept still valid? in other word,both my code and VM doesn't know when this thread will become really useless.
     I just want to know how does the lua VM deal with this problem.
 

here is my test code just for reference:
    lua_State* L = luaL_newstate();
    luaL_openlibs(L);
    lua_State* T = lua_newthread(L);
    lua_gc(L,LUA_GCCOLLECT,0);
    luaL_dofile(T,"test.lua");
after invoke lua_gc, this new thread pointer T still valid, and test.lua executed successfully.
 
                                      thanks


使用下一代的 MSN Messenger。 立即尝试!