> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/holoscan/sdk-user-guide/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/holoscan/sdk-user-guide/_mcp/server.

# holoscan::LockFreeQueue

> Lock-free queue implementation using MoodyCamel's ConcurrentQueue.

```cpp showLineNumbers={false}
template <typename T>
class LockFreeQueue
```

Lock-free queue implementation using MoodyCamel's ConcurrentQueue.

This is a high-performance lock-free MPMC (Multiple Producer Multiple Consumer) queue that uses per-producer sub-queues for optimal concurrency.

Thread Safety:

* Fully thread-safe for concurrent enqueue and dequeue operations
* No locks or blocking operations (wait-free for producers, lock-free for consumers)
* Safe to call from multiple threads simultaneously

Ordering Guarantees:

* Maintains FIFO order per-producer (items from the same thread stay ordered)
* Does NOT guarantee global FIFO order across multiple producers
* Items from different threads may be interleaved in any order

Performance Characteristics:

* Excellent throughput with minimal contention
* size\_approx() returns an estimate that may be stale immediately after return

```cpp showLineNumbers={false}
#include <holoscan/data_logger_queue.hpp>
```

**Template parameters**

**`T`** `typename`

The type of elements stored in the queue

---

**Inherits from:** `holoscan::DataLoggerQueue< T >` (public)

---

## Constructors

### LockFreeQueue \[#lockfreequeue]

```cpp showLineNumbers={false}
holoscan::LockFreeQueue<T>::LockFreeQueue(
    size_t capacity
)
```

Construct a lock-free queue with the specified capacity.

**Parameters**

**`capacity`** `size_t`

The target maximum capacity (note: ConcurrentQueue treats this as a hint)

---

---

## Methods

### try\_enqueue \[#tryenqueue]

```cpp showLineNumbers={false}
bool holoscan::LockFreeQueue<T>::try_enqueue(
    T &&item
) override
```

Attempt to enqueue an item (thread-safe).

**Returns:** true if successfully enqueued, false if queue is full

**Parameters**

**`item`** `T &&`

The item to enqueue (will be moved)

---

### try\_dequeue \[#trydequeue]

```cpp showLineNumbers={false}
bool holoscan::LockFreeQueue<T>::try_dequeue(
    T &item
) override
```

Attempt to dequeue an item (thread-safe).

**Returns:** true if an item was dequeued, false if queue is empty

**Parameters**

**`item`** `T &`

Output parameter where the dequeued item will be moved

---

### size\_approx \[#sizeapprox]

```cpp showLineNumbers={false}
size_t holoscan::LockFreeQueue<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](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)

---

## Member variables

| Name     | Type                               | Description |
| -------- | ---------------------------------- | ----------- |
| `queue_` | `moodycamel::ConcurrentQueue< T >` |             |