lua-users home
lua-l archive

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


Am Di., 31. Okt. 2023 um 09:24 Uhr schrieb Thijs Schreijer
<thijs@thijsschreijer.nl>:
>

> imho it should be dealt with on a Lua level. I actually discussed this with Roberto during the 2022 Lua workshop, and he had some ideas like a "goto" for coroutines. So hopefully we'll see this fixed in the next Lua version.
>

I would be surprised if this would work in Lua at all, as coroutines
in Lua are by principle cooperatively multitasking, not in "any
preemtive way"... .

If you solve it from Lua level, it is no problem at all: In my
applications it is necessary, that the user invokes "sys.sleep"
function in a regular Lua software, otherwise a Lua coroutine will
block the software ... but Lua will stop with "blocking error
message", if ca. 1000 Lua commands are excuted without such
"sys.sleep" .... (usign the standard hook by lua_sethook -
LUA_MASKCOUNT).

You will also run into such problems, if you want to allow Lua to
handle Lua commands arriving through some external / e. g. some serial
communications inteface from time to time. To handle such "external
Lua commands" in some clearly protected way you need a well defined
new stack...and also the "current stack" must be well defined. If the
Lua user wants to allow such "external event handling", then somwhere
in the "basic Loop function" of the Lua code a command
lua.executeexternals must be invoked... .

... why Lua does not support pre-emptive multithreading is explained
very clearly in Roberto's book Programming in Lua... . I think he is
very correct and adding pre-emptive multithreading to Lua sound a bit
like a "Halloween proposal" to me, sorry.... . I am not a big friend
of pre-emptive multitasking, also not in Windows... . If you like
pre-emptive things so much, you can without problems start Lua on
different pre-emptive machines of your operating system (like e. g.
Windows...).