cameron314 / cameron314/concurrentqueue
RFE: add capacity() method to query ConcurrentQueue and BlockingConcurrentQueue about actual capacity
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 12.5k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I'm using ConcurrentQueue and BlockingConcurrentQueue with preallocated queue size and, as described at https://github.com/cameron314/concurrentqueue#preallocation-correctly-using-try_enqueue, I'm using the constructor overload that accepts the minimum number of elements (N) and the maximum number of explicit and implicit producers.
In such case the actual capacity of the queue is computed internally.
I think it would be useful to have a capacity() method to verify what was the internal computation result, mostly for debug purposes.
My use case:
I'm building a unit test in debug mode (also with gcov code instrumentation, so the code runs much slower than the optimized version!). Such unit test is constructing a BlockingConcurrentQueue using the constructor overload that accepts the minimum number of elements (N) and the maximum number of explicit producer and I request a minimal size of 16384 items. The try_enqueue() method fails after enqueing about 4000-4400 items (the exact number varies from run to run and is not deterministic).
I would expect to be very far away from internal queue limits. Moreover in my unit test I have only 1 producer (with IMPLICIT token) and 1 consumer (with EXPLICIT token).
Having a capacity() method might help me to get to to the root of the problem perhaps.
Thanks!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the ConcurrentQueue and BlockingConcurrentQueue constructors that accept the minimum element count and producer limits, then trace how the internal capacity is computed. Review the existing try_enqueue() behavior and the reported unit-test scenario; done means a capacity() method exposes the computed capacity for both queue types and its behavior is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100