lua-users home
lua-l archive

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


> What release of Lua 5.1 are you using?

It's not what I use, it's what I used. I used 5.1.4.

> maybe you can
> simply change the limit LUAI_MAXCCALLS in luaconf.h

That will simply postpone the error. Our system is designed to run for
years and the ceiling will eventually be hit.


> Note that the change was the result of a bug in Lua 5.1:
>  http://www.lua.org/bugs.html#5.1.2-4


Well, maybe nCcalls was moved to the lua_State for other reasons, but
it is the only solution for a working multi threaded/coroutine system
in Lua.

>From above bug report:

> Patch: The 'nCcalls' counter should be shared by all threads. (That is, it should be declared in the 'global_State' structure, not in 'lua_State'.)

What is the logic behind this statement?
By moving nCcalls to the global structure, you in effect invalidate
all design that map coroutines to native threads.

Is it my explanation of the problem that is not sufficient?
Please let me know.

>  To understand this issue properly, is there really a mismatch in the call counter?

No, there is not a mismatch, but the locations where the nCcalls
variable is saved in variable oldnCcalls on the C stack will be wrong
when using multiple threads resulting in restoring it to an invalid
value later.

Assuming two thread/coroutines, named T1 and T2:

nCcalls is initially 0

T1 -> luaD_rawrunprotected -> save 0 in oldnCcalls and increment
nCcalls -> Lua Script -> C function that suspends

T2 -> luaD_rawrunprotected -> save 1 in oldnCcalls and increment
nCcalls -> Lua Script -> C function that suspends

T1 resumes -> luaD_rawrunprotected restores nCcalls to 0.

T2 resumes -> luaD_rawrunprotected restores nCcalls to 1 i.e. the
error I have tried to explain.

There is a very simple solution to the problem. Move variable nCcalls
into lua_State.
If nCcalls is in lua_State, then the above sequence would have been:

T1 -> luaD_rawrunprotected -> save 0 in oldnCcalls and increment
nCcalls -> Lua Script -> C function that suspends

T2 -> luaD_rawrunprotected -> save 0 in oldnCcalls and increment
nCcalls -> Lua Script -> C function that suspends

T1 resumes -> luaD_rawrunprotected restores nCcalls to 0.

T2 resumes -> luaD_rawrunprotected restores nCcalls to 0.