[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: 答复: A problem about coroutine's status
- From: Scott Vokes <vokes.s@...>
- Date: Sun, 29 Mar 2009 10:15:30 -0400
2009/3/29 lee <leeyacn@126.com>:
> Ok, it looks direct.
> To me, the difference between running and normal is obscure.
> What "normal" means ?
A coroutine's status is normal when it has been resumed, but has
itself resumed another, so it isn't the most directly active one. It's
running, but it's not the result of coroutine.running().
=====
local sub_cr =
coroutine.create(function(caller)
print("in sub-coroutine")
print(" -- sub_coroutine status: "
.. coroutine.status(coroutine.running()))
print(" -- caller status: "
.. coroutine.status(caller))
end)
local caller_cr =
coroutine.create(function(to_call)
print("in caller coroutine, about to resume
sub_coroutine")
coroutine.resume(to_call, coroutine.running())
print("back in caller")
print(" -- caller status: "
.. coroutine.status(coroutine.running()))
end)
coroutine.resume(caller_cr, sub_cr)
===== yields =====
> dofile("/tmp/lua-268182el")
in caller coroutine, about to resume sub_coroutine
in sub-coroutine
-- sub_coroutine status: running
-- caller status: normal
back in caller
-- caller status: running
Hope that helps,
Scott Vokes