[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: lua_lock() question
- From: Dibyendu Majumdar <mobile@...>
- Date: Sat, 9 May 2015 10:27:03 +0100
The core Lua api functions have a lua_lock() / lua_unlock() call
bracketing each api function. The default implementation does nothing
but I presume these stubs are for users who wish to ensure that the
same Lua state can be used by multiple OS threads.
I have noticed that the way these calls are implemented they will not
work reliably. For instance:
LUA_API void lua_settable (lua_State *L, int idx) {
StkId t;
lua_lock(L);
api_checknelems(L, 2);
t = index2addr(L, idx);
luaV_settable(L, t, L->top - 2, L->top - 1);
L->top -= 2; /* pop index and value */
lua_unlock(L);
}
If luaV_settable() threw an exception (i.e. performed a longjmp) then
the lua_unlock() will never be called. Is this a correct assessment or
am I missing something?
If above is true then the only way this would work was if Lua was
compiled in C++, the throw implementation was switched to C++
exception handling, and the locks were implemented with appropriate
auto destruction semantics.
Regards
Dibyendu