Closed devingryu closed 5 months ago
Yes, try_enqueue cannot allocate any memory, and there needs to be space in the producer's block index as well as a block itself.
Have a look at the three-argument constructor to make sure enough blocks are allocated when producing from multiple threads.
An index size of 64 or greater should be fine here.
Thanks for your kind answer! The problem is solved, but I have one more question to ask.
Is there a reason for defining the Initial Block Index Size separately in struct Trait? If we just define the Initial Capacity and Block Size, can't we also determine the required Initial Block Index Size?
The index is per producer. We could in theory deduce the largest index possibly required in the worst case that all blocks are in one producer, and use that for all producers, but that's just not how I had designed it originally.
I wasn't aware that index is per producer. Now I understand why you designed in that way.
Thanks!
I've run this block of code, and this never ends after printing
count:1024
. Changing capacity to larger value(4096, 8192...) doesn't make any changes to output.What am I missing? Thanks in advance.
Edit: I found that increasing
IMPLICIT_INITIAL_INDEX_SIZE
in Trait solves the issue by investigating code. Specifically,min(BLOCK_SIZE * IMPLICIT_INITIAL_INDEX_SIZE, capacity)
elements are accepted bytry_enqueue()
.Is this the correct way to contain over 1024 elements with implicit producer?