Back to lua_close in lstate.c

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Back to lua_close in lstate.c

Diego Nehab-3
Hi,

I am assuming now that luai_userstateclose(L) will block
until all threads have been completed. Only then will it
destroy the userstate initialized by lua_iuserstateopen(L).

     LUA_API void lua_close (lua_State *L) {
       L = G(L)->mainthread;  /* only the main thread can be closed */
       luai_userstateclose(L);
       lua_lock(L);
       luaF_close(L, L->stack);  /* close all upvalues for this thread */
       luaC_separateudata(L, 1);  /* separate udata that have GC metamethods */
       L->errfunc = 0;  /* no error function during GC metamethods */
       do {  /* repeat until no more errors */
         L->ci = L->base_ci;
         L->base = L->top = L->ci->base;
         L->nCcalls = 0;
       } while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
       lua_assert(G(L)->tmudata == NULL);
       close_state(L);
     }

With this behavior, it makes sense to call
luai_userstateclose(L) before doing anything else in
lua_close. What is not cool is the lua_lock that comes right
after it.

Do we all agree that this lua_lock should be scraped?

Either there are no other threads running, in which case we
don't need concurrency control after the call to
luai_userstateclose(L), or there are threads running, in
which case destroying their lua_States will cause havoc anyways!

Regards,
Diego.
Reply | Threaded
Open this post in threaded view
|

Re: Back to lua_close in lstate.c

Diego Nehab-3
Hi,

Oh well. It is not enough to remove that lua_lock. There can
be *no* calls to lua_lock after luai_userstateclose() is
invoked...

Any ideas how to accomplish this?

[]s,
Diego.