lua-users home
lua-l archive

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


Rici Lake wrote:
> The currently running thread (and therefore its stack) are always part 
> of the gc root. So is the "main thread" (and its stack).

That's not how it works internally in Lua 5.1 anymore.
Have a look at markroot() in lgc.c. Nowhere does it mark L,
the running thread (that called luaC_step).

However a running thread should always have a reference in
the thread that resumed it and so on until the main thread
(which _is_ marked as part of the gc root).

> If there is no reference left to a coroutine and the coroutine yields, 
> then it will get garbage collected at some point.

Remove the '... and the coroutine yields ...'.

It's a common pitfall when using coroutines from C, to forget
holding a reference to the resumed coroutine. Then it's suddenly
deallocated and you get random crashes (or a nice error from