Last Updated: February 1, 2026
A thread-safe unbounded queue that never blocks. Multiple threads can enqueue and dequeue simultaneously without locks. Progress is guaranteed: if threads keep trying, operations eventually complete.
| Operation | Description | Expected Complexity |
|---|---|---|
enqueue(item) | Add item to the tail of the queue | O(1) amortized |
dequeue() | Remove and return item from head | O(1) amortized |
isEmpty() | Check if queue contains no items | O(1) |
enqueue() simultaneously without losing itemsdequeue() simultaneously without duplicate consumptionLock-free algorithms provide different levels of progress guarantees:
| Guarantee | Definition | Our Queue |
|---|---|---|
| Wait-free | Every operation completes in bounded steps | No |
| Lock-free | At least one thread makes progress | Yes |
| Obstruction-free | A thread makes progress if run in isolation | Yes |
Our Michael-Scott queue is lock-free: even if some threads stall, at least one thread always makes progress. It's not wait-free because a single operation might retry indefinitely if constantly preempted by other threads (though this is rare in practice).