The documentation is not very clear on how unsafe concurrent_queue::unsafe_size() is.
The doxygen comment in the file tbb/internal/concurrent_queue.h mentions:
Get size of queue; result may be invalid if queue is modified
concurrently
What I am interested in knowing is will it return a valid size at some point in the past, or may it return garbage ? (Provided that several threads are both reading and writing).
I am not interested in the exact value, but more on a “load” indication. I want to prevent my queue to explode in capacity when the consumer threads have a problem. I’d use concurrent_bounded_queue which as the name suggest has a capacity control, but I would lose the lock-free property.
You really should treat it as garbage because it is marked unsafe. I think it may actually return questionable numbers because if memory serves its really a difference between pushes and pops. However even if it were ‘safe’ it would still only return a number that was valid in the past, that’s one of the joys of wait free programming.
If you really need to reason about the counts store an atomic count in the class that holds the queue.
Is there a reason you are not using one of the tasking primitives in tbb instead of building your own?