Crates.io | greenie |
lib.rs | greenie |
version | 0.4.0 |
source | src |
created_at | 2020-01-07 14:35:17.633294 |
updated_at | 2020-01-11 13:55:04.351366 |
description | Green threads and coroutines in stable Rust |
homepage | |
repository | https://github.com/playXE/greenie |
max_upload_size | |
id | 196142 |
size | 72,970 |
Simple green threads in Rust programming language.
Mutex
,Condvar
others will be implemented later ( see TODO ).greenify
macro that inserts yield points in your functions.Preemptive scheduling
Implement FIFO schedulign algorithm
Implement RwLock
.
Futures
Condvar and Mutex example:
use greenie::channel::*;
use greenie::{greeny_main, Fiber};
#[greeny_main]
fn main() {
let chan_1 = Channel::<&'static str>::new(2);
let chan_2 = Channel::<&'static str>::new(2);
let fping = Fiber::new_capture(
|chan_1, chan_2| {
chan_1.push("ping");
println!("{}", chan_2.pop().unwrap());
chan_1.push("ping");
println!("{}", chan_2.pop().unwrap());
chan_1.push("ping");
println!("{}", chan_2.pop().unwrap());
},
(chan_1.clone(), chan_2.clone()),
);
let fpong = Fiber::new_capture(
|chan_1, chan_2| {
chan_2.push("pong");
println!("{}", chan_1.pop().unwrap());
chan_2.push("pong");
println!("{}", chan_1.pop().unwrap());
chan_2.push("pong");
println!("{}", chan_1.pop().unwrap());
},
(chan_1.clone(), chan_2.clone()),
);
fpong.start().unwrap();
fping.start().unwrap();
}
For more examples read documentation or examples/