The open-coroutine
is a simple, efficient and generic stackful-coroutine library.
Still under development, please do not
use this library in the production
environment !
Only support hook several system calls
.
add dependency to your Cargo.toml
```toml
[dependencies]
open-coroutine = "x.y.z" ```
enable hooks
rust
fn main() {
//step2 enable hooks
open_coroutine::init();
//......
}
enjoy the performance improvement brought by open-coroutine
!
```rust use opencoroutine::{co, Yielder}; use std::os::raw::cvoid; use std::time::Duration;
extern "C" fn f1( yielder: &Yieldervoid>>, input: Option<&'static mut cvoid>, ) -> Option<&'static mut c_void> { println!("[coroutine1] launched"); None }
extern "C" fn f2( yielder: &Yieldervoid>>, input: Option<&'static mut cvoid>, ) -> Option<&'static mut c_void> { println!("[coroutine2] launched"); None }
fn main() { // because we used opencoroutine::co() // we don't need to call opencoroutine::init() // otherwise, don't forget opencoroutine::init() co(f1, None, 4096); co(f2, None, 4096); std::thread::sleep(Duration::frommillis(1)); println!("scheduler finished successfully!"); } ```
shell
cargo run --example hello