lua-users home
lua-l archive

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

On 9 May 2015 at 17:56, Roberto Ierusalimschy <> wrote:
> When a C function is called from Lua, there is (and there must be) a
> "reverse lock":
>    in function luaD_precall, file ldo.c:
>       lua_unlock(L);
>       n = (*f)(L);  /* do the actual call */
>       lua_lock(L);
> If there is a long jump, this 'lua_lock' is skipped, keeping the lock
> balanced. For instance:
>    C code -> enter lua_pcall:   lock
>    Lua code -> call C function: unlock
>    C code: enter lua_settabel:   lock
>      lua_settable throws an error, jumping back to lua_pcall
>    lua_pcall returns: unlock
> But it is easier to think differently. The main point is: you enter Lua,
> it locks. You leave lua, it unlocks. A long jump is not leaving Lua, so
> it does not have to unlock.

Ok, but does it mean to leave Lua? If Lua is unlocked, then at that
moment another
OS thread could be scheduled, and this may try to execute using the same
Lua state that was being used by another thread. Is this the desired