Overview
Syllabus
STACKFUL COROUTINE IN RUST ANOTHER ASYNC STORY
STACKFUL GENERATOR KEY FEATURES • detect current context type • Bend and yield with parameters
STACKFUL COROUTINE • coroutine is a special thread (user space / light) • scheduler running on multi-thread semantic blocking is not real blocking call API without directly yield keep the same interface as std library
DIFFERENCE WITH GENERATOR • coroutine is a special penerator • stackful coroutine can yield from any point directly to scheduler - always yield a "kernel request" when resume the scheduler send back the result init with Coroutine Local Storage
SYNC PRIMITIVE SUB SYSTEM • yield blocker kernel request • save the suspending coroutines within primitive internal queue - scheduling the coroutines on normal scheduler with work stealing support Semphore/Mutex/RwLock/Condvar/SyncFlap/MPSC
THE BLOCKER all sync primitives are implemented based on blocker • the blocker could return Timeout/Canceled/Ok - the blocker support running in thread context
COROUTINE CANCELLATION • we tripper a special panic when detect cancel • the cancel panic would be caught and we have chance to mark the coroutine as cancelled • can only detect cancel when switch from/to
Taught by
Rust