Skip to content

Use cached write index in pop assertion - #70

Merged
rigtorp merged 1 commit into
masterfrom
fix/pop-cached-index-assert
Nov 17, 2026
Merged

rigtorp merged 1 commit into
masterfrom
fix/pop-cached-index-assert

Conversation

@rigtorp

@rigtorp rigtorp commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Summary

Use the consumer-owned cached write index in pop()'s assertion. A successful front() already acquires the producer's write index when necessary and establishes that the cached index is ahead of the item being consumed.

- assert(writeIdx_.load(std::memory_order_acquire) != readIdx && ...);
+ assert(writeIdxCache_ != readIdx && ...);

This isolates the assertion idea from #45. Keep the successful-front() precondition and existing wraparound/capacity logic. The assertion is compiled out under NDEBUG; no Release performance improvement is claimed.

Extend the existing POSIX Debug death test to cover a non-empty queue that has never had front() called, as well as an empty queue. This checks the missing-front diagnostic in that case, not every possible precondition violation.

Evidence

  • Before: The new non-empty missing-front case fails its death-test expectation: the old assertion permits pop() and the child exits normally.
    After: Debug and Release test suites pass with GCC 16.2.1, including the Debug death tests and existing concurrent FIFO/wraparound coverage.
  • Pinned pre-commit hooks and git diff --check pass.

Merge Danger

Door: two-way

Blast Radius: assertions

Valid consumer operations retain their synchronization through front(). Debug builds detect the newly covered precondition violation earlier; Release behavior is unchanged.

@rigtorp
rigtorp merged commit 51fad1b into master Nov 17, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant