Thread Aware
Summary
A library for creating isolated affinities in Rust, allowing for safe and efficient data transfer between them.
This is useful in scenarios where you want to isolate data to different affinities, such as NUMA nodes, threads, or specific CPU cores. It can serve as a foundation for building a async runtime or a task scheduler that operates across multiple affinities. For example it can be used to implement a NUMA-aware task scheduler that transfers data between different NUMA nodes or a thread-per-core scheduler that transfers data between different CPU cores.
The way this would be used is by restricting how work can be scheduled on other affinities (threads,
NUMA nodes). If the runtime only allows work scheduling in a way that accepts work that can be
transferred (e.g. by using the [RelocateFnOnce] trait) and makes sure that transfer is called, it can
effectively isolate the affinities as the [ThreadAware] trait ensures the right level of separation if
implemented correctly.
ThreadAware is an 'infectious' trait, meaning that when you implement it for a type,
all of its fields must also implement [ThreadAware] and you must call their transfer methods.
However [ThreadAware] is provided for many common types, so you can use it out of the box for most cases.
Feature Flags
derive(default) – Re-exports the#[derive(ThreadAware)]macro from the companionthread_aware_macroscrate. Disable to avoid pulling in proc-macro code in minimal environments:default-features = false.
Examples
use ;
// Define a type that implements ThreadAware
Derive Macro Example
When the derive feature (enabled by default) is active you can simply
derive [ThreadAware] instead of writing the implementation manually.
use ;
If you disable default features (or the derive feature explicitly) you
can still implement [ThreadAware] manually as shown in the earlier example.
This crate was developed as part of The Oxidizer Project.