How tokio-rs/loom works
Loom is a Rust library for checking concurrent code by modeling and exploring possible executions. A user writes a model closure using Loom’s thread and synchronization APIs; the model runtime schedules permutations and detects invalid behaviors such as races or leaks. The graph includes the public primitive families and the internal execution, scheduling, and object-state layers. Relationships among unsampled runtime subsystems are omitted where the supplied excerpts and reference index do not establish a call.
Main entry points: sync/mod.rs Sync primitives · execution.rs Execution state · rt/mod.rs Runtime coordination · model.rs Model runner
Components 26
Modeling API
- Model runner
src/model.rs - Thread API
src/thread.rs - Future utilities
src/future/mod.rs - Cell API
src/cell/unsafe_cell.rs - Scheduling hints
src/hint.rs
Exploration Engine
- Runtime coordination
src/rt/mod.rs - Execution state
src/rt/execution.rs - Path exploration
src/rt/path.rs - Thread scheduler
src/rt/scheduler.rs - Thread state
src/rt/thread.rs - Operation locations
src/rt/location.rs
Modeled State
- Modeled object store
src/rt/object.rs - Atomic model
src/rt/atomic.rs - Allocation tracking
src/rt/alloc.rs - Lazy static state
src/rt/lazy_static.rs
Concurrency Primitives
- Sync primitives
src/sync/mod.rs - Atomic types
src/sync/atomic/mod.rs - Reference counting
src/sync/arc.rs - Mutexes
src/sync/mutex.rs - Read-write locks
src/sync/rwlock.rs - Channels
src/sync/mpsc.rs - Notifications
src/sync/notify.rs - Condition variables
src/sync/condvar.rs - Barriers
src/sync/barrier.rs - Modeled cells
src/cell/cell.rs
Other components
- Concurrent test author
Connections 26
- Concurrent test author → Model runner: defines model
README.md - Model runner → Runtime coordination: starts execution
src/model.rs - Thread API → Runtime coordination: uses runtime
src/thread.rs - Future utilities → Runtime coordination: waits via runtime
src/future/mod.rs - Cell API → Runtime coordination: models access
src/cell/unsafe_cell.rs - Scheduling hints → Thread API: yields through
src/hint.rs - Runtime coordination → Execution state: runs closures
src/rt/mod.rs - Execution state → Path exploration: branches through
src/rt/execution.rs - Execution state → Thread state: tracks threads
src/rt/execution.rs - Execution state → Modeled object store: tracks objects
src/rt/execution.rs - Execution state → Thread scheduler: dispatches scheduling
- Runtime coordination → Thread scheduler: switches threads
src/rt/mod.rs - Execution state → Operation locations: uses locations
src/rt/execution.rs - Atomic types → Atomic model: models operations
src/sync/atomic/mod.rs - Atomic model → Modeled object store: updates state
src/rt/atomic.rs - Sync primitives → Reference counting: exports type
src/sync/mod.rs - Sync primitives → Atomic types: exports types
src/sync/mod.rs - Sync primitives → Mutexes: exports type
src/sync/mod.rs - Sync primitives → Read-write locks: exports type
src/sync/mod.rs - Sync primitives → Channels: exports type
src/sync/mod.rs - Sync primitives → Notifications: exports type
src/sync/mod.rs - Sync primitives → Condition variables: exports type
src/sync/mod.rs - Sync primitives → Barriers: exports type
src/sync/mod.rs - Modeled cells → Cell API: uses cell implementation
src/cell/mod.rs - Lazy static state → Execution state: stores per execution
src/rt/lazy_static.rs - Allocation tracking → Execution state: tracks allocations
src/rt/execution.rs