If it were clear, questions like "what's the difference between
threads and coroutines" would never arise. The text may work for
you, but it's utterly misleading for me. First, I can only know that
Lua uses an idiosyntractic meaning for "thread" if I happen to have
read and understood the other relevant sections of the manual. Even
worse, the second sentence of 2.11 states: "A coroutine in Lua
represents an independent thread of execution. " Some may consider
that clear, but it's clear as mud to me, because "independent thread"
strongly implies to me that we're talking about multithreading
(whether implemented in
kernel or user space). (Even worse worse, look at the definition of
the type thread, which could not possibly be more obscure.) In my
view Lua coroutines are by definition _not_ independent, since they
must cooperate. It would be more accurate if not more clear to a)
remove all reference to threads, and b) call them distinct,
sequestered, or the like, but not "independent". Why not just use a
standard definition of coroutine? E.g. a coroutine is a subroutine
that supports suspend/resume operations and multiple entry points.
It has nothing to do with threads, unless you're willing to say that
every routine (function) is a thread. You could stipulate that every
jump represents a jump to a different "thread" but that seems kind of
pointless.