#stack #context #switch #switcher #light-weight #generator #userland

nightly switcher2

Lightweight userland context switches

1 unstable release

0.1.0 Aug 30, 2022

#3 in #userland

Apache-2.0/MIT

45KB
732 lines

Switcher2

A light-weight context switcher based on Switcheroo.


lib.rs:

Switcher2 provides lightweight context switches in Rust.

It consists of two parts:

  1. A stack implementation (currently only providing a fixed 8Mb stack).
  2. A generator implementation.

Example

use switcher2::stack::*;
use switcher2::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);
}

Dependencies

~220KB