yield now and busy polling optimization
Configuration
- Enable busy polling via features = ["busy-polling"] for monoio .
- Ensure timers are enabled with #[monoio::main(enable_timer = true)] or RuntimeBuilder::enable_timer() .
Usage
- Cooperative yield with futures_lite::future::yield_now().await inside task loops.
Behavior
- busy polling reduces latency/jitter for timer-driven workloads (especially monoio::time::sleep(Duration::from_secs(0)) ), at the cost of higher CPU; it’s opt-in.
- yield_now improves fairness by adding explicit yield points for long loops.
Example
- See examples/busy_polling.rs for side-by-side yield_now() and monoio::time::sleep(Duration::from_secs(0)) .
Notes
- yield_now is similar in spirit to tokio::task::yield_now .
- The implementation uses futures_lite::future::yield_now instead of a crate-local monoio::task::yield_now .
合并状态:未合并 关闭于 2025-10-21 2 条评论