[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Why does coroutine.create return a thread?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 21 Jun 2016 12:45:34 -0300
> > 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