lua-users home
lua-l archive

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


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.