BoundedPointerQueue class
A bounded, lock-free, multi-producer multi-consumer queue for pointers.
On this page
- Use
import ThinkMeta.ConcurrentTasks.Collections.BoundedPointerQueue;- Namespace
ThinkMeta::ConcurrentTasks::Collections- Platforms
- Windows, Linux
Syntax
template <typename T>
using BoundedPointerQueue = Cpp::Padded<_BoundedPointerQueue<T>>;Template parameters
Ttypename- The pointee type; the queue holds
T* and does not own them.
Remarks
Meant for cases where the number of elements is known and bounded, such as the scheduler's task queues. The capacity is set once, at run time, by Initialize and is a power of two. It must cover the maximum number of elements the use case can hold at once: enqueueing into a full queue is invalid use and leaves the queue unusable.
See also
Names
| Name | Description |
|---|---|
BoundedPointerQueue |
A bounded, lock-free, multi-producer multi-consumer FIFO of pointers.
Holds |
Constructors
BoundedPointerQueue
Constructs a queue without storage.
Syntax
BoundedPointerQueue() noexcept;Remarks
Initialize must succeed before the queue is used.
~BoundedPointerQueue
Frees the ring.
Syntax
~BoundedPointerQueue() noexcept;Remarks
Pointers still in the queue are not touched (not owned).
Methods
Initialize
Allocates the ring.
Syntax
bool Initialize(std::size_t capacity) noexcept;Parameters
capacitystd::size_t- Number of slots; must be a power of two and at least 2.
Return value
Type: bool
true on success; false if the memory could not be allocated.
Remarks
Call once, before the queue is shared.
See also
Capacity
The number of slots, 0 before Initialize.
Syntax
std::size_t Capacity() const noexcept;Return value
Type: std::size_t
The capacity passed to Initialize, or 0.
Enqueue
Enqueues a pointer.
Syntax
void Enqueue(T* ptr) noexcept;Parameters
ptrT*- Pointer to enqueue. Must not be
nullptr.
Remarks
Lock-free; callable from any number of threads at once. The queue must not be full (see the capacity rule above).
See also
Dequeue
Dequeues a pointer.
Syntax
T* Dequeue() noexcept;Return value
Type: T*
The dequeued pointer, or nullptr if the queue is empty.
Remarks
Lock-free; callable from any number of threads at once. An element whose Enqueue has not returned yet may still be missed.
See also
IsEmpty
Tells whether the queue looked empty a moment ago.
Syntax
bool IsEmpty() const noexcept;Return value
Type: bool
true if the head slot held no element.
Remarks
A snapshot for heuristics (e.g. whether another consumer is worth waking): it can be stale as soon as it returns, and it does not order anything. An element whose Enqueue has not returned yet may be missed, as in Dequeue.
Generated from ThinkMeta.ConcurrentTasks.API @ c7663c4 (2026-11-19).