- net tcplistner
- bindすると
- mioListnerを初期化する
- Wacher::newが実行される。
- mioのEventを監視するReactorが起動する。
- Reactor::registerで、watcher::new経由で渡ってきたmioListenerを監視対象に登録している。
- Reactorが起動すると別スレッドを起動してmain_loopに入る。
- main_loop内部でpoller::pollを実行し、監視対象からEventが来ていないかを監視。
- eventが来たらentriesからeventと紐づいたentryを取得し、eventの種類(読み込み、書き込み)に応じて対応するwakerをentryから取得、wakeを実行(この部分理解が曖昧)
- main_loop内部でpoller::pollを実行し、監視対象からEventが来ていないかを監視。
- mioのEventを監視するReactorが起動する。
- incoming.nextすると
- bindすると
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct Heap { | |
values: Vec<i64>, | |
} | |
// ヒープの条件 | |
// 頂点のvの親頂点をpとした時,key[p]>=key[v]が成立する | |
// 木の高さをhとした時,木の深さをh-1以下の部分については完全二分木 | |
// 木の高さをhとした時,木の深さhの部分については,頂点が左詰めされている | |
impl Heap { |
-
共通
- Executorというtraitをimplする型が,tokioのtaskをspawnする責務を担っている(よってhyperはtokio runtimeでないと動かない)。ただしExecutorはtraitになっているので、実装の差し替えが考慮されている?(外部からcustom executorを差し込めるかは不明)
- なんかそれっぽいissueはある(hyperium/hyper#1854)
- Executor traitはtokio_executorのものなのでtokioからは逃れられないのだ...
- wakerどっかで呼んでるはずだけどどこ?
- Executorというtraitをimplする型が,tokioのtaskをspawnする責務を担っている(よってhyperはtokio runtimeでないと動かない)。ただしExecutorはtraitになっているので、実装の差し替えが考慮されている?(外部からcustom executorを差し込めるかは不明)
-
hyper serverメモ
- Serverは内部的にspawn_allというものを格納したServer構造体を返している(https://github.com/hyperium/hyper/blob/master/src/server/mod.rs)
-
tokioにはsingle thread schedulerとmulti thread schedulerがある
- single thread scheduler
-
中にSchedulerPrivというものが入っていて、これが実質的なスケジューリングをしているっぽい。
-
MpscQueueで管理(Multi-Provider-Single-Consumer-Queue)
-
parkとunparkってなんなんだ〜〜〜
- tokio_executor曰く,現在のスレッドのブロッキングやアンプロッキングの抽象化らしい。
- blocked parkはunparkによってunblockされるらしい。すなわちparkするとThreadはsleepする。
- tokio_executor曰く,現在のスレッドのブロッキングやアンプロッキングの抽象化らしい。
-
- single thread scheduler
-
Tokio Reactorはmio::Pollを呼んでいるらしい。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 参考 | |
// https://rust-lang.github.io/async-book/02_execution/04_executor.html | |
// https://keens.github.io/blog/2019/07/07/rustnofuturetosonorunnerwotsukuttemita/ | |
use std::{ | |
future::{Future}, | |
pin::Pin, | |
sync::mpsc::{sync_channel, Receiver, SyncSender}, | |
sync::{Arc, Mutex}, | |
task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, |