#coroutine

sys context

Cooperative multitasking for Rust using Boost.Context

12 releases (6 stable)

Uses old Rust 2015

3.0.0 Jan 25, 2023
2.1.0 Feb 2, 2018
2.0.1 Jan 7, 2018
2.0.0 Jun 6, 2017
0.1.3 Oct 11, 2015

#379 in Concurrency

Download history 33/week @ 2023-12-11 43/week @ 2023-12-18 49/week @ 2023-12-25 6/week @ 2024-01-01 106/week @ 2024-01-08 74/week @ 2024-01-15 43/week @ 2024-01-22 113/week @ 2024-01-29 99/week @ 2024-02-05 70/week @ 2024-02-12 94/week @ 2024-02-19 267/week @ 2024-02-26 147/week @ 2024-03-04 190/week @ 2024-03-11 146/week @ 2024-03-18 157/week @ 2024-03-25

654 downloads per month
Used in 13 crates (10 directly)

MIT/Apache

335KB
4.5K SLoC

GNU Style Assembly 2.5K SLoC // 0.5% comments Assembly 1.5K SLoC // 0.3% comments Rust 581 SLoC // 0.1% comments

context-rs

Build Status Build status License

This project offers an easy interface to the famous Boost.Context library and thus provides the building blocks for higher-level abstractions, like coroutines, cooperative threads (userland threads) or an equivalent to C# keyword yield in C++.

API documentation

Usage

To use context, first add this to your Cargo.toml:

[dependencies]
context = "3.0"

And then add this to your source files:

extern crate context;

Performance

The performance heavily depends on the architecture and even on the operating system. A context switch itself is usually as fast as a regular function call though and can thus be viewed as one.

To see this for yourself run cargo bench resume. You can then compare the results of the resume benchmarks (which uses Context::resume()) to the results of resume_reference_perf (which uses regular function calls).

Platforms

Architecture Linux (UNIX) Windows MacOS X iOS
i386 SYSV (ELF) MS (PE) SYSV (MACH-O) -
x86_64 SYSV, X32 (ELF) MS (PE) SYSV (MACH-O) -
arm (aarch32) AAPCS (ELF) AAPCS (PE) - AAPCS (MACH-O)
arm (aarch64) AAPCS (ELF) - - AAPCS (MACH-O)
mips1 O32 (ELF) - - -
ppc32 SYSV (ELF), XCOFF - SYSV (MACH-O) -
ppc64 SYSV (ELF), XCOFF - SYSV (MACH-O) -

Format: ABI (binary format). Source: Boost.Context

Dependencies

~0.4–385KB