作者回复: tokio 会在每个 CPU core 上运行一个 OS thread 来处理调度。后面的内容讲到,async 和 await 其实就是语法糖,await 的点在编译时都会编译成状态机的一部分,所以一个内部拥有多个 await 的 async 函数,里面是一个复杂的状态机,按 await 的顺序依次 poll future。在 poll 的时候,如果 pending,executor 会将其挂起。executor 再去取下一个可以执行的 Future。如果没有可执行的 Future,才会去"偷" 别的线程队列中的 Future 执行。
作者回复: 很简单,因为标准库的 MutexGuard 不是 Send: https://doc.rust-lang.org/src/std/sync/mutex.rs.html#204,而 tokio 的实现了 Send:https://docs.rs/tokio/latest/tokio/sync/struct.MutexGuard.html。
作者回复: playground 把常见的 crate 都添加了