如何实现一个实用的光纤调度? [英] How to implement a practical fiber scheduler?

查看:155
本文介绍了如何实现一个实用的光纤调度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用协程为基地,实施玩具调度非常基础。但我认为这是关于整体异步调度过于简单化的看法。有一整套孔在我的心中缺少的。

I know the very basics about using coroutines as a base and implementing a toy scheduler. But I assume it's oversimplified view about asynchronous schedulers in whole. There are whole set of holes missing in my thoughts.

如何让CPU从运行的运行空闲/等待调度?一些纤维只是睡觉,其他人等待来自操作系统的输入。

How to keep the cpu from running a scheduler that's running idle/waiting? Some fibers just sleep, others wait for input from operating system.

推荐答案

您就需要IO操作复用到一个基于事件的接​​口(选择/民意调查),因此您可以利用操作系统做的等待,同时仍然能够调度其他纤维。选择/民调有超时参数 - 对于想睡觉纤维,可以创建一个使用选择/投票表决该选项来模拟睡眠呼叫的优先级队列

You'd need to multiplex io operations into an event based interface(select/poll), so you can leverage the OS to do the waiting, while still being able to schedule other fibers. select/poll have a timeout argument - for fibers that want to sleep, you can create a priority queue that uses that option of select/poll to emulate a sleep call.

试图服务,它阻塞操作纤维(调用读/写/睡眠等)。除非你在安排本地线程每个光纤直接将无法正常工作 - 哪一种跳动的目的

Trying to serve fibers that does blocking operations (call read/write/sleep etc). directly won't work unless you schedule each fiber in a native thread - which kind of beats the purpose.

请参阅 http://swtch.com/libtask/ 的工作落实。

这篇关于如何实现一个实用的光纤调度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆