The Lua coroutine scheduler question

Look at a few examples of Lua coroutine scheduler Coroutine, all is the users themselves, but seem to be in an infinite loop in the interruption of ready Coroutine by executing resume (operation). My question is,

(1)If all coroutines are yield, the scheduler is in idle, execution cycle of death without the release of CPU. If you use it to achieve a server, such idle is certainly not ideal.
(2)Can consider to let the scheduler blocking in the ready coroutine number 0, until a coroutine meet ready conditions to be awakened again. But in that case, scheduling model seems to have degenerated into asynchronous message format: task check message queue, blocking is empty. As the direct use asynchronous messaging, why bother to achieve such a complex coroutine scheduler?

Coroutine beginner, please Master pointing.

One example here

Started by Carrie at February 07, 2016 - 12:00 AM

Yield does not seem to be really to hang it back and saved the state program stack will continue running your wrong not to try

Posted by Michelle at February 13, 2016 - 12:44 AM

Thank you to answer. If it wasn't really hang, happened to all coroutines are yield, the behavior of the scheduler is constantly polling, is? I want to know a theoretical answer.

Of course, also need the actual environmental verification, but the scheduler is Lua programmers to design, I'm afraid I is based on a false premise, validation will be blind. May not really so polling?

Posted by Carrie at February 25, 2016 - 1:04 AM

A bit is not very understand your point.
An corountine if yield has been so it is suspended
But your scheduler not put it resume it has since resumed why said is empty loop.

Posted by Michelle at February 26, 2016 - 1:16 AM

My understanding is that when a coroutine suspends, control back to the scheduler, then the scheduler to resume the other coroutine. After N a coroutine is yield, did not reach to the condition in the resume, this time the scheduler should do what?

The above example, the scheduler is to N a coroutine each polling, whether can be resume, meet the execution of it, one by one.

The Linux kernel process scheduling and it is different, if all processes are hung up, the kernel should wait for interrupt, rather than a CPU constantly polling.

In the host C/C++ program support, Lua scheduler can be implemented as a OS process scheduling similar mechanisms, in all the coroutine suspends, Lua State where the thread is blocked waiting for other threads to complete after the call, send message / event, coroutines and resume in accordance with the terms of the.

But that modify the coroutine scheduler of feeling is very complex, it seems too many software message queue, state machines of the treatment, the amount of code is not worth the extra. So I want to know the actual use has no more perfect a coroutine scheduler, neither polling, do not degenerate into a multi task message queue similar model.

Posted by Carrie at March 06, 2016 - 1:44 AM

You can consider whether the condition in the resume written in corountine external
For all corountine resume wrote in a corountine
If all the conditions are not met the scheduler yield

Posted by Michelle at March 13, 2016 - 3:44 AM

The scheduler of coroutine is yield, then who is to resume it?

To ask this question from the perspective of C/C++ host program:
Lua State is executed in a thread to host a program specified, when all the coroutine is yield, this thread what to do: blocking wait, or polling idle? CPU control flow to where?

Posted by Carrie at March 20, 2016 - 3:40 AM

This itself is just a thread at this time, the main thread is still running

Posted by Michelle at March 28, 2016 - 3:48 AM

The problem is not the. The problem is Lua the thread should have what kind of action, in addition to blocking usually sense or polling, there is no better solution.

Posted by Carrie at January 02, 2017 - 11:38 PM

If you choose to continue polling, obviously is a waste of time CPU,
If the Lua thread then blocking, another thread after work to cross thread trigger resume condition change, also awaken threads (Lua coroutine scheduler), and a logical flow and asynchronous callback mode become fragmented, coroutines advantage reflected how?

Posted by Carrie at January 09, 2017 - 10:46 PM