lua-users home
lua-l archive

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


> > Is a coroutine the function that you pass into `coroutine.create`?
> > 
> > Is a `thread` the execution environment that is running the coroutine?
> > 
> >   thread = coroutine + stack + current state
> 
> I would say that a coroutine is simply a specific use case of a Lua thread: 
> 
> - you create it with `coroutine.create`
> - you run it with `coroutine.resume`
> - it can return control to the caller thread for any point of its execution using `coroutine.yield`.
> 
> Actually, the coroutine is the thread, not the function passed to `coroutine.create`.

Right: couroutine is a specific use case of a Lua thread. As it is the
only use of threads inside Lua code, we can say that, looking from Lua,
coroutine = thread. The difference is only relevant (visible) for those
working in the C (API) level.

-- Roberto