Skip to content

Document try_enqueue implicit producer index limit (#418)#446

Open
PavelGuzenfeld wants to merge 2 commits intocameron314:masterfrom
PavelGuzenfeld:fix/try-enqueue-implicit-index-docs-418
Open

Document try_enqueue implicit producer index limit (#418)#446
PavelGuzenfeld wants to merge 2 commits intocameron314:masterfrom
PavelGuzenfeld:fix/try-enqueue-implicit-index-docs-418

Conversation

@PavelGuzenfeld
Copy link

Summary

  • Added documentation to ConcurrentQueueDefaultTraits::IMPLICIT_INITIAL_INDEX_SIZE explaining the relationship between BLOCK_SIZE, IMPLICIT_INITIAL_INDEX_SIZE, and the maximum elements per implicit producer when using try_enqueue
  • Added clarifying note on the try_enqueue method that pre-allocating blocks via the constructor does not increase the block index size
  • Added implicit_producer_index_limit unit test demonstrating the limit and both workarounds (use enqueue() or increase IMPLICIT_INITIAL_INDEX_SIZE)

Test plan

  • Unit test implicit_producer_index_limit passes (8 iterations, all green)
  • Full test suite builds with gcc:14

Fixes #418

…le-cast compliance

Projects using -Wold-style-cast and -Wuseless-cast (common in modern C++ codebases
with strict warning policies) cannot compile concurrentqueue without warnings.

Changes:
- lightweightsemaphore.h: Replace C-style casts with static_cast in timed_wait,
  waitWithPartialSpinning, waitManyWithPartialSpinning, and signal methods
- blockingconcurrentqueue.h: Replace C-style casts with static_cast for
  sema->signal, sema->waitMany, sema->tryWaitMany, sema->availableApprox calls
  and constructor MAX_SEMA_SPINS; replace C-style pointer casts in assert with
  reinterpret_cast
- concurrentqueue.h: Suppress -Wuseless-cast around hash_thread_id static_cast
  that is needed for cross-platform correctness but redundant on 64-bit

Tested clean with GCC 14/15, C++17/20/23, using -Wall -Wextra -Wpedantic -Werror
-Wold-style-cast -Wuseless-cast -Wconversion -Wsign-conversion and other strict flags.
…ameron314#418)

try_enqueue() fails around BLOCK_SIZE * IMPLICIT_INITIAL_INDEX_SIZE elements
per implicit producer because the block index (not the blocks) must grow,
which requires allocation that try_enqueue refuses to do. Pre-allocating
blocks via the constructor does not help.

Added documentation comments near IMPLICIT_INITIAL_INDEX_SIZE in the default
traits and near the try_enqueue method explaining the limit and workarounds.
Added implicit_producer_index_limit unit test demonstrating the issue and
verifying both workarounds (enqueue() and larger IMPLICIT_INITIAL_INDEX_SIZE).
@PavelGuzenfeld PavelGuzenfeld force-pushed the fix/try-enqueue-implicit-index-docs-418 branch from 911509e to 1a7c45f Compare March 17, 2026 18:50
@PavelGuzenfeld
Copy link
Author

Hi @cameron314, just a friendly ping on this PR. Would you have a chance to take a look when convenient? Happy to address any feedback. Thank you!

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.

When there is lot of enqueue , it fails

1 participant