木头云 2593213d9c Fix FreeBSD shm_unlink failure by adding '/' prefix in remove()
Problem: Tests fail on the second run on FreeBSD with ShmTest.RemoveByName failing.
After the first test run completes, subsequent runs fail because shared memory
objects are not properly removed.

Root cause: FreeBSD's shm_unlink() is stricter than Linux about POSIX compliance.
The remove(char const * name) function was calling shm_unlink() without the '/'
prefix, while acquire() was using '/'+name format. This inconsistency caused:
- Linux: Silently tolerates both /name and name formats
- FreeBSD: Strictly requires /name format, shm_unlink("name") fails

When shm_unlink() fails to remove the shared memory object:
1. First test run creates /remove_by_name_test_1
2. Test calls shm::remove("remove_by_name_test_1")
3. shm_unlink("remove_by_name_test_1") fails on FreeBSD (missing '/')
4. Shared memory object remains in the system
5. Second test run tries to reuse the same name -> conflict -> test fails

Solution:
1. Fix remove(char const * name) to prepend '/' to the name for consistency
   with acquire() function, ensuring POSIX compliance
2. Add error checking for all shm_unlink() calls to log failures with errno

This ensures proper cleanup on FreeBSD and maintains compatibility with Linux.

Changes:
- Modified remove(char const * name) to use '/'+name format
- Added error logging for all three shm_unlink() calls
- Now consistent with POSIX requirement: shared memory names must be /somename

Tested on FreeBSD 15: Multiple consecutive test runs now pass without failures.
2025-12-06 07:20:33 +00:00
.github/workflows Update c-cpp.yml 2021-07-10 13:52:44 +08:00
3rdparty Fixed memory access exception in multithreading. 2023-10-28 16:44:16 +08:00
demo mingw: use lower case windows.h 2025-11-17 09:56:49 +00:00
include/libipc docs(shm): add semantic comments for release/remove and fix double-free in tests 2025-11-30 05:28:48 +00:00
src Fix FreeBSD shm_unlink failure by adding '/' prefix in remove() 2025-12-06 07:20:33 +00:00
test fix(test): replace C++17 structured bindings with C++14 compatible code 2025-11-30 11:16:03 +00:00
.gitignore disable warning C4858 2023-10-28 16:44:16 +08:00
CMakeLists.txt Supplement similar demo under linux. 2023-10-28 16:44:16 +08:00
LICENSE 调整目录结构,隔离include路径,修正tls在win下的问题 2020-09-13 17:29:14 +08:00
performance.xlsx performance.xlsx 更新图示说明 2021-10-17 14:32:38 +08:00
README.md Add FreeBSD platform support (fixes #156) 2025-11-29 10:55:54 +00:00

cpp-ipc (libipc) - C++ IPC Library

MIT licensed Build Status Build status Vcpkg package

A high-performance inter-process communication library using shared memory on Linux/Windows/FreeBSD.

  • Compilers with C++17 support are recommended (msvc-2017/gcc-7/clang-4)
  • No other dependencies except STL.
  • Only lock-free or lightweight spin-lock is used.
  • Circular array is used as the underline data structure.
  • ipc::route supports single write and multiple read. ipc::channel supports multiple read and write. (Note: currently, a channel supports up to 32 receivers, but there is no such a limit for the sender.)
  • Broadcasting is used by default, but user can choose any read/ write combinations.
  • No long time blind wait. (Semaphore will be used after a certain number of retries.)
  • Vcpkg way of installation is supported. E.g. vcpkg install cpp-ipc

Usage

See: Wiki

Performance

Environment Value
Device Lenovo ThinkPad T450
CPU Intel® Core™ i5-4300U @ 2.5 GHz
RAM 16 GB
OS Windows 7 Ultimate x64
Compiler MSVC 2017 15.9.4

Unit & benchmark tests: test
Performance data: performance.xlsx

Reference


使用共享内存的跨平台Linux/Windows/FreeBSDx86/x64/ARM高性能IPC通讯库

  • 推荐支持C++17的编译器msvc-2017/gcc-7/clang-4
  • 除STL外无其他依赖
  • 无锁lock-free或轻量级spin-lock
  • 底层数据结构为循环数组circular array
  • ipc::route支持单写多读,ipc::channel支持多写多读【注意目前同一条通道最多支持32个receiversender无限制
  • 默认采用广播模式收发数据,支持用户任意选择读写方案
  • 不会长时间忙等(重试一定次数后会使用信号量进行等待),支持超时
  • 支持Vcpkg方式安装,如vcpkg install cpp-ipc

使用方法

详见:Wiki

性能

环境
设备 联想 ThinkPad T450
CPU 英特尔® Core™ i5-4300U @ 2.5 GHz
内存 16 GB
操作系统 Windows 7 Ultimate x64
编译器 MSVC 2017 15.9.4

单元测试和Benchmark测试: test
性能数据: performance.xlsx

参考