[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: What's the difference between a "coroutine" and a "thread" in Lua?
- From: David Kastrup <dak@...>
- Date: Sun, 12 Aug 2007 09:52:36 +0200
Adrien de Croy <adrien@qbik.com> writes:
> I agree
>
> in the context of OS threads, it refers to an independent call stack
> and context.
What do you mean with context?
> Process memory is shared and accessible to all threads of a process.
> Stack variables however, belong to the thread whose stack they
> reside in.
>
> re-entrable code vs yielding or being pre-empted are independent
> concepts to that of a thread.
Uh what? A thread that is neither preempted nor yields is not a thread.
> Since a lua thread provices another call stack, and has its own
> context, I think it qualifies to be called a thread.
I don't see an "own context" in any sensible meaning of the word, and
of course coroutines all have their own stack. That's the whole point
of them. The difference between coroutines and threads is that
coroutines have a single flow of control. That means that there is no
necessity for any locking in coroutines. The sequence of operations
is uniquely determined by yielding. That is no different to
subroutine calls, _except_ that yielding does not leave the call stack
of the current coroutine and reenters at the same place.
Essentially wrapping a function body into one endless loop with a
yield at the end is pretty much the same from a transfer of control
view than returning.
--
David Kastrup, Kriemhildstr. 15, 44793 Bochum