Skip to content

Instantly share code, notes, and snippets.

View tawashichan's full-sized avatar

tawashichan tawashichan

View GitHub Profile
#[derive(Debug)]
struct Heap {
values: Vec<i64>,
}
// ヒープの条件
// 頂点のvの親頂点をpとした時,key[p]>=key[v]が成立する
// 木の高さをhとした時,木の深さをh-1以下の部分については完全二分木
// 木の高さをhとした時,木の深さhの部分については,頂点が左詰めされている
impl Heap {
  • 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を実行(この部分理解が曖昧)
    • incoming.nextすると
@tawashichan
tawashichan / hyper_memo.md
Created December 9, 2019 04:36
hyper_memo
  • 共通

    • Executorというtraitをimplする型が,tokioのtaskをspawnする責務を担っている(よってhyperはtokio runtimeでないと動かない)。ただしExecutorはtraitになっているので、実装の差し替えが考慮されている?(外部からcustom executorを差し込めるかは不明)
      • なんかそれっぽいissueはある(hyperium/hyper#1854)
      • Executor traitはtokio_executorのものなのでtokioからは逃れられないのだ...
    • wakerどっかで呼んでるはずだけどどこ?
  • hyper serverメモ

@tawashichan
tawashichan / tokio_memo.md
Last active December 9, 2019 04:38
tokio_memo
  • 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 Reactorはmio::Pollを呼んでいるらしい。

@tawashichan
tawashichan / future_sample.rs
Last active December 18, 2019 06:31
future_sample
// 参考
// 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},