Project 4: Implement a Thread-Safe Queue (Arc + Mutex)
A thread-safe bounded queue using
Arc<Mutex<VecDeque<T>>>that multiple threads can safely push to and pop from.
Quick Reference
| Attribute | Value |
|---|---|
| Primary Language | Rust |
| Alternative Languages | None |
| Difficulty | Level 3: Advanced |
| Time Estimate | 1 week |
| Knowledge Area | Concurrency / Synchronization |
| Tooling | Rust std::sync |
| Prerequisites | Projects 1-3, basic concurrency understanding |
What You Will Build
A thread-safe bounded queue using Arc<Mutex<VecDeque<T>>> that multiple threads can safely push to and pop from.
Why It Matters
This project builds core skills that appear repeatedly in real-world systems and tooling.
Core Challenges
- Sharing queue across threads → maps to Arc for shared ownership
- Preventing data races → maps to Mutex for synchronized access
- Handling blocking semantics → maps to Condvar for thread coordination
- Avoiding deadlocks → maps to understanding lock ordering
Key Concepts
- Concurrency Primitives: “The Rust Programming Language” Chapter 16
- Arc and Mutex: “Programming Rust” Chapter 19
- Lock-Free Programming: “Rust Atomics and Locks” by Mara Bos
- Producer-Consumer Pattern: Any concurrency textbook
Real-World Outcome
Deliver a working demo with observable output that proves the feature is correct.
Implementation Guide
- Reproduce the simplest happy-path scenario.
- Build the smallest working version of the core feature.
- Add input validation and error handling.
- Add instrumentation/logging to confirm behavior.
- Refactor into clean modules with tests.
Milestones
- Milestone 1: Minimal working program that runs end-to-end.
- Milestone 2: Correct outputs for typical inputs.
- Milestone 3: Robust handling of edge cases.
- Milestone 4: Clean structure and documented usage.
Validation Checklist
- Output matches the real-world outcome example
- Handles invalid inputs safely
- Provides clear errors and exit codes
- Repeatable results across runs
References
- Main guide:
RUST_BORROW_CHECKER_LIFETIME_PHILOSOPHY.md - “Rust Atomics and Locks” by Mara Bos