Skip to content

Repository files navigation

cpp-ipc

High-performance C++17 header-only IPC (Inter-Process Communication) library built on POSIX shared memory and lock-free queues.

Features

  • Lock-free queues — SPSC, MPSC, and MPMC implementations for shared memory
  • Zero-copy messaging — pass data between processes without serialization overhead
  • Shared memory segments — lifecycle-managed POSIX shared memory with reference counting
  • Synchronization primitives — futex, eventfd, spinlock, and configurable wait strategies
  • Channel abstraction — compile-time dispatch over queue mode (SPSC / MPSC / MPMC)
  • CUDA helpers — optional GPU-accelerated batch CRC32 and memory transfers (stubs)

Requirements

  • Compiler: C++17 (GCC 9+, Clang 10+)
  • Build system: CMake 3.20+
  • Platform: Linux (x86-64, aarch64)
  • Kernel: Linux 4.0+ (for futex syscall and eventfd)
  • CUDA: optional, CUDA 11+ toolkit if enabling IPC_HAS_CUDA

Quick Start

Build

cmake -B build -S .
cmake --build build

Hello World

./build/hello_world

Run tests

./build/ipc_tests

Run benchmarks

./build/bench_latency
./build/bench_throughput

Usage

Shared memory queue (standalone)

#include "ipc/queue/spsc_queue.hpp"

struct Message { uint64_t id; char data[56]; };

constexpr size_t CAP = 1024;
size_t mem_size = ipc::queue::SPSCQueue<Message>::RequiredMemory(CAP);
std::vector<char> mem(mem_size);
auto* queue = ipc::queue::SPSCQueue<Message>::Create(mem.data(), CAP);

// Producer
Message msg{42, "hello"};
queue->TryPush(msg);

// Consumer
Message received{};
if (queue->TryPop(received)) { /* use received */ }

IPC channel (cross-process)

#include "ipc/ipc.hpp"

// Process A (owner)
auto ch = ipc::channel::Channel<MyMsg, ipc::QueueMode::SPSC>::Create("/my_channel");
auto producer = ch.GetProducer();
producer.Send(msg);

// Process B (client)
auto ch = ipc::channel::Channel<MyMsg, ipc::QueueMode::SPSC>::Connect("/my_channel");
auto consumer = ch.GetConsumer();
auto msg = consumer.Receive();

Queue modes

// Single producer, single consumer
ipc::channel::Channel<T, ipc::QueueMode::SPSC>

// Multi producer, single consumer
ipc::channel::Channel<T, ipc::QueueMode::MPSC>

// Multi producer, multi consumer
ipc::channel::Channel<T, ipc::QueueMode::MPMC>

Project Structure

include/ipc/
├── channel/       Channel, Producer, Consumer APIs
├── queue/         SPSC, MPSC, MPMC lock-free queues
├── shm/           Shared memory segment, lifecycle, allocator
├── sync/          Spinlock, futex, eventfd, wait strategies
├── util/          Backoff, cache-line alignment, perf counters
└── vcokg_adaptor/ Platform/atomic/concurrency abstraction layer

src/               Compiled sources (segment, futex)
tests/             Unit tests and benchmarks
examples/          Hello world demo
cuda/              Optional CUDA batch operations

Thread Safety

  • All queue TryPush / TryPop operations are lock-free and thread-safe within their documented discipline
  • SPSCQueue requires exactly one producer and one consumer thread
  • MPSCQueue supports multiple concurrent producers, single consumer
  • MPMCQueue supports multiple concurrent producers and consumers
  • Shared memory segments are safe for multi-process access via atomic reference counting

License

MIT

About

cpp-ipc is a high-performance C++17 IPC library using POSIX shared memory and lock-free SPSC/MPSC/MPMC queues. All data-plane ops run in userspace, with futex used only for blocking. SPSC achieves sub-200ns latency with zero CAS. Compile-time QueueForMode dispatch, offset-based pointers, five wait strategies

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages