lua-users home
lua-l archive

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


On 23-Dec-17 00:41, Sean Conner wrote:
   Getting back to Lua, Lua is based upon a VM, so it has its own concept of
RIP and RSP.  A call to lua_newstate() (or luaL_newstate()) returns a new
Lua VM context, which can be likened to a "process" in that it manages the
resources and contains at least one "unit of execution." The function
lua_newthread() creates a new "unit of execution" within the current Lua VM,
which the Lua documentation calls a "thread" but is more like a "coroutine"
although in any case, it's a "unit of execution" that needs to be
explicitely switched to.  And this "unit of execution" only has meaning to
the Lua VM---it is totally unrelated to the system notion of "units of
execution" (like threads or processes).

Thanks for this clear comparison between Lua 'threads' (coroutines) and native threads. I have always been too lazy to look up how Lua coroutines actually work and I did not visualize the Lua VM as a sort of CPU (though in retrospective it should have been obvious).

--
  Enrico