#thread #fiber #green

nightly coroutine

Coroutine Library in Rust

14 unstable releases (6 breaking)

Uses old Rust 2015

0.8.0 Mar 24, 2017
0.7.1 Mar 21, 2017
0.6.0 Jul 29, 2016
0.5.0 Mar 26, 2016
0.1.2 Apr 19, 2015

#426 in Concurrency

Download history 14/week @ 2024-02-19 46/week @ 2024-02-26 10/week @ 2024-03-04 33/week @ 2024-03-11 13/week @ 2024-03-18 319/week @ 2024-04-01

367 downloads per month
Used in 2 crates

MIT/Apache

75KB
2K SLoC

coroutine-rs

Build Status crates.io crates.io

Coroutine library in Rust

[dependencies.coroutine]
git = "0.5.0"

Usage

Basic usage of Coroutine

extern crate coroutine;

use std::usize;
use coroutine::asymmetric::Coroutine;

fn main() {
    let coro: Coroutine<i32> = Coroutine::spawn(|me,_| {
        for num in 0..10 {
            me.yield_with(num);
        }
        usize::MAX
    });

    for num in coro {
        println!("{}", num.unwrap());
    }
}

This program will print the following to the console

0
1
2
3
4
5
6
7
8
9
18446744073709551615

For more detail, please run cargo doc --open.

Goals

  • Basic single threaded coroutine support

  • Asymmetric Coroutines

  • Symmetric Coroutines

  • Thread-safe: can only resume a coroutine in one thread simultaneously

Notes

  • Currently this crate can only be built with Rust nightly because of some unstable features.

  • Basically it supports arm, i686, mips, mipsel and x86_64 platforms, but we have only tested in

    • OS X 10.10.*, x86_64, nightly

    • ArchLinux, x86_64, nightly

Thanks

  • The Rust developers (context switch ASM from libgreen)

Dependencies

~560KB