Lightweight OS core for coordinating medical-care robots with safe concurrency.
This repository is scoped to the three mandatory components in Project B:
- Task queue
- Zone access control
- Health monitor
The implementation prioritizes correctness and clarity over performance, consistent with project rules.
This repository is aligned with:
Project-B.pdfproject_B_guidelines.mdAGENTS.md
Implemented mandatory behaviors:
- Multiple robots concurrently request and consume tasks.
- Zone access is mutually exclusive (no two robots in the same zone simultaneously).
- Heartbeat timeout detection marks robots offline.
Explicit non-goals:
- No preemption
- No deadlock prevention algorithms
- No complex scheduling policies
src/task_queue.rsTaskQueue:Mutex<VecDeque<Task>>+Condvar- Supports non-blocking (
try_pop) and blocking (pop_blocking_or_closed) task fetch - Provides queue shutdown behavior (
close) that unblocks all waiting consumers
src/zones.rsZoneAccess:Mutex<Vec<Option<RobotId>>>+ per-zoneCondvars- Uses a fixed, 1-indexed zone table sized at construction time
- Enforces single-owner occupancy per zone;
acquireblocks until the zone is free
src/health_monitor.rsHealthMonitor:Mutex<HealthState>whereHealthStatestores both heartbeat timestamps and the offline set- Keeps heartbeat updates and offline detection in one coherent critical section
src/sim.rs- Demo runner (
run_demo): 3 robots, 2 zones, deterministic offline target (robot 1) - Benchmark runner (
run_benchmark): single parameterized run, boxed summary output - Stress sweep runner (
run_stress): iterates robot/task/zone sets, aligned table output - Benchmark validation uses a fixed seen-table keyed by task id instead of a channel
- The background health-monitor thread is only spawned for
offline-demobenchmark/stress runs
- Demo runner (
src/main.rs- CLI entry point; subcommands: (no args) demo,
bench,stress,--help
- CLI entry point; subcommands: (no args) demo,
src/logging.rslog_dev!macro: debug-only structured logs (no-op in release builds)
src/types.rs- Shared type aliases:
TaskId,RobotId,ZoneId;Taskstruct
- Shared type aliases:
tests/cli_demo.rs- Integration tests: verify demo summary fields, zone safety, and offline detection
- A task is consumed at most once.
- A zone is occupied by at most one robot at a time.
- Offline robots are detected by heartbeat timeout.
- Shared mutable state is protected by synchronization primitives.
- Lock scopes are short, with no nested lock cycles in core logic.
Required project gates:
cargo build --release
cargo testAdditional recommended verification:
cargo test --releasecargo run --release -- --helpUsage summary:
project_blaze(no subcommand): run demoproject_blaze bench [robots] [tasks_per_robot] [zones] [work_ms] [validate] [offline-demo]project_blaze stress [robot_sets] [task_sets] [zone_sets] [work_ms] [validate] [offline-demo]
Argument notes:
robot_sets,task_sets,zone_setsare comma-separated lists, for example1,2,4.- Use
-to keep default sets in stress mode. validateenables extra runtime safety checks in benchmark/stress output.offline-demo,--offline-demo, andofflineare equivalent flag aliases.
Defaults:
- bench:
robots=4 tasks_per_robot=25 zones=2 work_ms=5 - stress:
robots=1,2,4,8,12 tasks_per_robot=10,25,50 zones=1,2,4 work_ms=5
This section is intentionally step-by-step so graders can verify required behaviors quickly.
cargo build --release
cargo testExpected:
- Build succeeds.
- All unit and integration tests pass.
Run demo in release mode:
cargo run --releaseExpected summary fields:
DEMO SUMMARYzone_violation=falseoffline_target=1detected=trueoffline_robots={1}
Interpretation:
- Concurrency is active (
per_robot_donevector covers all robots). - Zone exclusivity holds (
zone_violation=false). - Offline detection is deterministic for grading (
offline_target=1and detected).
For thread-by-thread logs (optional):
cargo runDebug builds print detailed queue/zone/health transitions.
Standard benchmark:
cargo run --release -- bench 4 25 2 5 validateExpected key rows:
zone_violation=falseduplicate_tasks=false
Offline benchmark:
cargo run --release -- bench 4 50 2 20 validate --offline-demoExpected:
offline_robots >= 1zone_violation=falseduplicate_tasks=false
Standard stress sweep:
cargo run --release -- stress 1,2,4 10,25 1,2 5 validateOffline stress sweep:
cargo run --release -- stress 1,2,4 10,25 1,2 5 validate --offline-demoExpected across rows:
zone_violation=falseduplicate_tasks=false- In offline mode:
offline_robots >= 1is acceptable
Important semantics:
- Demo mode uses deterministic offline target verification.
- Benchmark/stress offline mode validates timeout behavior under workloads and may mark multiple robots offline by the end of a run.
robotstasks_totalper_robot_donemax_zone_occzone_violationoffline_targetdetectedoffline_robots
The benchmark command prints a boxed summary with these fields:
robotstasks_per_robotzonestotal_taskselapsed_msthroughputavg_zone_wait_µscpu_user_scpu_sys_smax_occupancyzone_violationduplicate_tasksoffline_robots
The stress command prints the same metrics as aligned table columns using the shorter labels shown in the CLI (tasks/r, tput(t/s), wait_µs, and so on).
Platform note:
cpu_user_sandcpu_sys_sare populated on Unix platforms.- Non-Unix builds output
NAin CPU columns.
project_blaze/
|-- Cargo.toml
|-- README.md
|-- DIAGRAMS.md
|-- CLAUDE.md
|-- AGENTS.md
|-- project_B_guidelines.md
|-- Project-B.pdf
|-- written_report_draft.tex
|-- src/
| |-- main.rs
| |-- sim.rs
| |-- task_queue.rs
| |-- zones.rs
| |-- health_monitor.rs
| |-- logging.rs
| `-- types.rs
`-- tests/
`-- cli_demo.rs
- Architecture and flow diagrams:
DIAGRAMS.md
- Official requirements remain the source of truth (
Project-B.pdf,project_B_guidelines.md). - Simulation timings are tuned for demonstrability and reproducibility, not realism.