#linux #context #nightly #fn #windows #macos

nightly switcheroo

Lightweight userland context switches

12 releases

0.2.9 May 7, 2021
0.2.8 Apr 8, 2021
0.2.6 Feb 4, 2021
0.2.3 Jan 23, 2021
0.1.1 Sep 4, 2020
Download history 13/week @ 2022-10-13 15/week @ 2022-10-20 23/week @ 2022-10-27 37/week @ 2022-11-03 18/week @ 2022-11-10 18/week @ 2022-11-17 14/week @ 2022-11-24 19/week @ 2022-12-01 23/week @ 2022-12-08 7/week @ 2022-12-15 8/week @ 2022-12-22 10/week @ 2022-12-29 19/week @ 2023-01-05 13/week @ 2023-01-12 17/week @ 2023-01-19 14/week @ 2023-01-26

64 downloads per month
Used in async-wormhole

Apache-2.0/MIT

46KB
729 lines

Switcheroo

Documentation

This library is heavily inspired by https://github.com/edef1c/libfringe.

Currently only works in Rust nightly.

Switcheroo provides lightweight context switches in Rust. It runs on Windows, MacOs and Linux (x64 & AArch64).

Example

use switcheroo::stack::*;
use switcheroo::Generator;

fn  main() {
    let stack = EightMbStack::new().unwrap();
    let mut add_one = Generator::new(stack, |yielder, mut input| {
        loop {
            if input ==  0 {
                break;
            }
            input = yielder.suspend(input +  1);
        }
    });

    assert_eq!(add_one.resume(2), Some(3));
    assert_eq!(add_one.resume(127), Some(128));
    assert_eq!(add_one.resume(0), None);
    assert_eq!(add_one.resume(0), None);
}

Performance

On my Macbook Pro 15" (Late 2013) each context switch is comparable to a function call (sub-nanosecond).

Developer Experience

Switcheroo tries hard to not let the context switching disturb default Rust behaviour on panics and unwinds. The displayed backtrace should stretch across the context switch boundary.

When dropping a non-empty stack, it will be unwind to free any resources allocated on it.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~36KB