Holoscan SDK v3.11.0

Template Class OrderedQueue

Base Type

template<typename T>
class OrderedQueue : public holoscan::DataLoggerQueue<T>

Ordered queue implementation using mutex-protected std::queue.

This queue uses a mutex to serialize all operations, ensuring both thread-safety and strict global FIFO ordering across all producers and the single consumer.

Thread Safety:

  • Fully thread-safe for concurrent enqueue and dequeue operations

  • Uses a mutex to serialize access (blocking if contended)

  • Safe to call from multiple producer threads and a single consumer thread simultaneously

Ordering Guarantees:

  • Maintains strict global FIFO order across ALL producers

  • Items are dequeued in the exact order they were enqueued

  • Guaranteed temporal ordering regardless of which thread enqueued the item

Performance Characteristics:

  • Lower throughput than lock-free queues under high contention

  • Predictable latency (no worst-case scenarios from lock-free algorithms)

  • size_approx() returns the exact size (not approximate, despite the name)

  • Capacity is a strict limit (will reject enqueue when full)

  • Mutex is held during the entire move operation: if T has expensive move semantics (beyond simple pointer swaps), this may increase contention under heavy load

  • Best suited for scenarios where ordering is critical and producer contention is moderate

Template Parameters

T – The type of elements stored in the queue

Public Functions

inline explicit OrderedQueue(size_t capacity)

Construct an ordered queue with the specified capacity.

Parameters

capacity – The maximum capacity (strict limit, unlike ConcurrentQueue)

inline virtual bool try_enqueue(T &&item) override

Attempt to enqueue an item (thread-safe).

Parameters

item – The item to enqueue (will be moved)

Returns

true if successfully enqueued, false if queue is full

inline virtual bool try_dequeue(T &item) override

Dequeue an item from the queue.

Without this pattern, the naive item = std::move(queue_.front()) would destroy the old item value inside the mutex, causing deadlock: [Queue Mutex] → [GIL] → [Thread Join].

Trade-off: One extra move for movable types, one extra copy for copy-only types.

Note

Uses std::optional to defer destruction of the output parameter’s previous value until after the mutex is released. This prevents deadlock when T’s destructor acquires other locks (e.g., GILGuardedPyObject acquiring the Python GIL).

Parameters

item – Output parameter. Its destructor runs outside the critical section.

Returns

true if an item was dequeued, false if queue was empty

inline virtual size_t size_approx() const override

Get size of the queue (thread-safe).

Note: The accuracy of this value depends on the implementation:

  • LockFreeQueue: Returns an approximation that may be stale by the time it’s returned

  • OrderedQueue: Returns the exact size at the moment the mutex was acquired

Returns

Number of items in the queue (approximation or exact, depending on implementation)

Previous Class OrConditionCombiner
Next Class OutputContext
© Copyright 2022-2026, NVIDIA. Last updated on Feb 4, 2026