Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla ConcurrentQueue

From Leeroopedia
Knowledge Sources
Domains Concurrency, Data Structures
Last Updated 2026-02-15 05:00 GMT

Overview

ConcurrentQueue.h provides a high-performance, lock-free, multi-producer multi-consumer queue implementation for C++11, adapted from the moodycamel library for use within CARLA.

Description

This is a third-party header-only library by Cameron Desrochers (Simplified BSD license) that implements a lock-free concurrent queue. The queue supports multiple producers and multiple consumers without requiring mutexes or locks, achieving high throughput through careful use of C++11 atomics and cache-friendly data structures. The implementation uses per-producer implicit sub-queues to minimize contention between threads. It has been slightly adapted for use by CARLA, as noted in the source comments. The file is approximately 3647 lines and contains the full implementation including the ConcurrentQueue template class, producer/consumer tokens, and internal memory management.

Usage

Use this queue when high-throughput, thread-safe communication between producer and consumer threads is needed within the CARLA simulator, such as passing sensor data between the simulation thread and streaming threads.

Code Reference

Source Location

  • Repository: CARLA
  • File: LibCarla/source/third-party/moodycamel/ConcurrentQueue.h

Signature

namespace moodycamel {

template<typename T, typename Traits = ConcurrentQueueDefaultTraits>
class ConcurrentQueue {
public:
    explicit ConcurrentQueue(size_t capacity = 6 * BLOCK_SIZE);

    bool enqueue(T const& item);
    bool enqueue(T&& item);
    bool try_dequeue(T& item);

    template<typename It>
    size_t try_dequeue_bulk(It itemFirst, size_t max);

    size_t size_approx() const;
    // ...
};

} // namespace moodycamel

Import

#include "third-party/moodycamel/ConcurrentQueue.h"

I/O Contract

Method Return Type Description
enqueue(item) bool Enqueues an item; returns true on success
try_dequeue(item) bool Attempts to dequeue an item; returns true if an item was dequeued
try_dequeue_bulk(it, max) size_t Dequeues up to max items into iterator; returns count dequeued
size_approx() size_t Returns approximate number of items in the queue

Usage Examples

#include "third-party/moodycamel/ConcurrentQueue.h"

moodycamel::ConcurrentQueue<int> queue;

// Producer thread
queue.enqueue(42);

// Consumer thread
int item;
if (queue.try_dequeue(item)) {
    // process item
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment