lua-users home
lua-l archive

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


On Fri, Jul 3, 2020 at 9:29 PM Stefan <> wrote:
> Am 03.07.2020 um 18:49 schrieb Francisco Olarte:
> > Although you maay be able to yield from the main thread I do not think
> > this is totally supported given:
> > "coroutine.isyieldable ()
> > Returns true when the running coroutine can yield.
> > A running coroutine is yieldable if ***it is not the main thread****
> > and it is not inside a non-yieldable C function. "
> Hmm.. this doesn't seem to be correct. Here is a test program[1] that
> loads und runs the following buffer in the main thread:
> print(coroutine.isyieldable(),coroutine.isyieldable(coroutine.running()))

... exhaustive example....

Stefan , although it may work some times I do not think, given how
easy it is to avoid it, resuming the main thread is a good idea. A BAD
program does not need to malfunction in every situation, just in one.

In asymmetric coroutines y normally assume a coroutine can be resumed
when it is suspended, and it is suspended when it is just created but
not started or has called yield, neither of which is true in main, I
see it as started from creation and not being able to yield because it
has no one to yield to.

Given lua uses the same struct in the C API it may well be posible to
call the functions and obtain some aparently correct bu tsubtly
corrupted results. You can use them, but IMO you are inflicting
problems in yourself.

Your exhaustive exploration of ( what I personally consider bizarre )
ways of (ab)using the API is good, but I am not personally going to
analyze it too much. Just seeing the difference in behaviours between
versions makes me worry you are hitting some kind of what in C is
called "undefined behaviour" at its finest.

To me it seems whenever you call lua_resume the API assumes you are
doing it on a resumable coroutine, and acts accordingly without
checking too much, so sometimes it does the right thing, sometimes it
does not. Paraphrasing AST, it is a servant, not a nanny. And nearly
something for yield.

Francisco Olarte.