concurrentqueue icon indicating copy to clipboard operation
concurrentqueue copied to clipboard

Pre-allocation of producers

Open frankist opened this issue 8 months ago • 3 comments

As far as I understood, the constructor:

	ConcurrentQueue(size_t minCapacity, size_t maxExplicitProducers, size_t maxImplicitProducers)

uses the maxExplicitProducers and maxImplicitProducers to set the initial number of blocks. However, it does not preallocate producers (via add_producer). This means that try_enqueue can still malloc a producer when it is called.

Could the constructor mentioned above also include the following snippet in its body to minimise the chance of malloc when using try_enqueue?

for(size_t i = 0; i != maxImplicitProducers; ++i) {
  auto* p = add_producer(create<ImplicitProducer>(this));
  p->inactive.store(true, std::memory_order_relaxed);
}

frankist avatar May 09 '25 13:05 frankist