[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: What's the difference between a "coroutine" and a "thread" in Lua?
- From: David Kastrup <dak@...>
- Date: Tue, 14 Aug 2007 12:29:54 +0200
Adrien de Croy <firstname.lastname@example.org> writes:
> I'd also query how any subsystem that runs on a pre-empted OS can
> guarantee serialization of calls to a coroutine subsystem without
> binding to a single CPU and running only in a single OS thread (or
> using OS lock primitives).
Look, Lua threads return _values_ to "resume" when "yield"ing. There
is no way you can have called and called "thread" run simultaneously:
when the caller continues, the callee has _yielded_, and _passed_ a
value to the caller, and vice versa.
Your confusion clearly shows that calling Lua threads "threads" was a
bad idea. They pass control together with values, so they can't
possibly run simultanously.
To do that, one would have to split "yield" into two: a "yieldvalue"
which gets passed to the calling thread, and a parameterless "yield".
Everything in between could then run in parallel.
I doubt that the complications would make for much usefulness,