Crate preemptive_threads

Crate preemptive_threads 

Source
Expand description

A no_std preemptive multithreading library built from scratch for OS kernels and embedded systems.

This library provides preemptive multithreading capabilities without requiring the standard library, making it suitable for embedded systems, OS kernels, and other resource-constrained environments.

§Features

  • std-shim: Enable compatibility layer for standard library
  • x86_64: Enable x86_64 architecture support
  • arm64: Enable ARM64 architecture support
  • riscv64: Enable RISC-V 64-bit architecture support
  • full-fpu: Enable full floating point unit save/restore
  • mmu: Enable memory management unit features like guard pages
  • work-stealing: Enable work-stealing scheduler implementation
  • hardened: Enable security hardening features

§Architecture

The library is organized around several key abstractions:

  • Architecture-specific context switching and interrupt handling
  • Pluggable schedulers with different algorithms
  • Safe memory management for thread stacks and resources
  • Preemptive scheduling with configurable time slices

Re-exports§

pub use arch::Arch;
pub use arch::DefaultArch;
pub use atomic_scheduler::AtomicScheduler;
pub use atomic_scheduler::ATOMIC_SCHEDULER;
pub use error::ThreadError;
pub use error::ThreadResult;
pub use kernel::Kernel;
pub use kernel::SpawnError;
pub use mem::ArcLite;
pub use mem::Stack;
pub use mem::StackPool;
pub use mem::StackSizeClass;
pub use platform_timer::init_preemption_timer;
pub use platform_timer::stop_preemption_timer;
pub use platform_timer::preemption_checkpoint;
pub use safe_api::exit_thread as safe_exit;
pub use safe_api::yield_now;
pub use safe_api::Mutex;
pub use safe_api::MutexGuard;
pub use safe_api::ThreadBuilder as OldThreadBuilder;
pub use safe_api::ThreadHandle;
pub use safe_api::ThreadPool;
pub use scheduler::Scheduler as OldScheduler;
pub use scheduler::SCHEDULER;
pub use stack_guard::ProtectedStack;
pub use stack_guard::StackGuard;
pub use stack_guard::StackStats;
pub use stack_guard::StackStatus;
pub use sync::exit_thread;
pub use sync::yield_thread;
pub use thread::Thread as OldThread;
pub use thread::ThreadState as OldThreadState;
pub use thread_new::Thread;
pub use thread_new::ThreadId;
pub use thread_new::ThreadState;
pub use thread_new::JoinHandle;
pub use thread_new::ThreadBuilder;
pub use thread_new::ReadyRef;
pub use thread_new::RunningRef;
pub use time::Duration;
pub use time::Instant;
pub use time::Timer;
pub use time::TimerConfig;
pub use time::PreemptGuard;
pub use time::IrqGuard;
pub use observability::ThreadMetrics;
pub use observability::SystemMetrics;
pub use observability::ResourceLimiter;
pub use observability::ThreadProfiler;
pub use observability::HealthMonitor;
pub use observability::ObservabilityConfig;
pub use observability::init_observability;
pub use observability::cleanup_observability;
pub use security::SecurityConfig;
pub use security::SecurityViolation;
pub use security::SecurityStats;
pub use security::SecurityFeature;
pub use security::init_security;
pub use security::get_security_stats;
pub use security::configure_security_feature;
pub use sched::Scheduler as NewScheduler;
pub use sched::CpuId;
pub use sched::RoundRobinScheduler;
pub use sched::DefaultScheduler;

Modules§

arch
Architecture abstraction layer for context switching and interrupt handling.
atomic_scheduler
context
context_full
error
errors
Comprehensive error handling for the threading system.
kernel
Kernel abstraction for managing the threading system.
mem
Memory management abstractions for thread safety.
observability
Observability and monitoring for the threading system.
perf
Performance optimization infrastructure and implementations.
platform_timer
Platform-specific timer implementations for preemptive scheduling
preemption
safe_api
sched
New scheduler implementations with lock-free data structures.
scheduler
security
Security and hardening features for the threading system.
signal_safe
stack_guard
sync
thread
thread_new
New thread abstraction with RAII and memory safety.
time
Time management and timer interrupt handling.

Macros§

assert_valid_cas_ordering
Assert that memory orderings are valid for compare-exchange operations.
assert_valid_load_ordering
Assert that a memory ordering is valid for load operations.
assert_valid_store_ordering
Assert that a memory ordering is valid for store operations.
cfi_protected_call
Macro for CFI-protected function calls.
cross_domain_access
Macro for safe cross-domain access.
isolated_thread
Macro for creating isolated thread domain.
preemption_point
Cooperative preemption points - insert these in long-running code
protected_stack
Stack allocation with automatic guard setup
record_fence
Convenience macro for recording memory fences.
record_read
Convenience macro for recording memory reads.
record_write
Convenience macro for recording memory writes.
return_address_guard
Macro for return address protection.
stack_canary_guard
Macro to automatically check stack canaries.