https://github.com/playxe/greenie
Green threads and generators in Rust
https://github.com/playxe/greenie
Last synced: 17 days ago
JSON representation
Green threads and generators in Rust
- Host: GitHub
- URL: https://github.com/playxe/greenie
- Owner: playXE
- License: mit
- Created: 2020-01-07T14:27:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-26T08:34:39.000Z (about 5 years ago)
- Last Synced: 2025-02-12T20:48:37.092Z (2 months ago)
- Language: Rust
- Size: 12.8 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# greenie
Simple green threads in Rust programming language.# Features
- Generators in stable Rust!
- Synchronization primitives: `Mutex`,`Condvar` others will be implemented later ( see TODO ).
- Fast.
- Semi-automatic scheduling using `greenify` macro that inserts yield points in your functions.# TODO
- Preemptive scheduling.
- Implement `RwLock`.
- Futures.# Example
Condvar and Mutex example:
```rust
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.send("ping");
println!("{}", chan_2.recv().unwrap());
chan_1.send("ping");
println!("{}", chan_2.recv().unwrap());
chan_1.send("ping");
println!("{}", chan_2.recv().unwrap());
},
(chan_1.clone(), chan_2.clone()),
);
let fpong = Fiber::new_capture(
|chan_1, chan_2| {
chan_2.send("pong");
println!("{}", chan_1.recv().unwrap());
chan_2.send("pong");
println!("{}", chan_1.recv().unwrap());
chan_2.send("pong");
println!("{}", chan_1.recv().unwrap());
},
(chan_1.clone(), chan_2.clone()),
);fpong.start().unwrap();
fping.start().unwrap();
}
```
For more examples read [documentation](https://docs.rs/greenie/) or `examples/`