[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua_lock() question
- From: Roberto Ierusalimschy <roberto@...>
- Date: Sat, 9 May 2015 13:56:50 -0300
> Agreed - my point was that this discipline is not being followed, i.e.
> there will not be a corresponding lua_unlock() call due to the longjmp
> leading to a lock that will not be released.
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.
-- Roberto