Repository navigation
Conversation
Boost.Interprocess has no process-shared unnamed semaphores on macOS, so interprocess_semaphore falls back to a spin emulation that sleeps between polls. Every SHM notification on macOS was delivered with up to a scheduler tick of delay (about 3 ms average), and idle listener threads kept waking. Add RobustInterprocessSemaphore, used by RobustInterprocessCondition on macOS only. It keeps the 32-bit counter layout of Boost's spin_semaphore, blocks with os_sync_wait_on_address(OS_SYNC_WAIT_ON_ADDRESS_SHARED) on macOS 14.4+, and falls back to Boost's spin_wait on older systems. Each kernel wait is capped at 1 ms so posts from processes using the old spin_semaphore, which don't wake waiters, are still seen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Maurice <mauricepurnawan@gmail.com>
Contributor
Author
|
I also believe the long-term fix should be made upstream in Boost itself, so I have opened an issue to track it: boostorg/interprocess#285 |
MiguelCompany
requested changes
Nov 16, 2026
Compare size and alignment of the whole semaphore with boost::interprocess::interprocess_semaphore, instead of only comparing std::atomic<uint32_t> with uint32_t. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Maurice <mauricepurnawan@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Maurice <mauricepurnawan@gmail.com>
MiguelCompany
self-requested a review
November 16, 2026 10:47
1 task done
|
Tested this PR on top of the two Fast DDS versions used by ROS 2 on macOS. Results below, for reference for the 3.2.x backport and a possible 2.14.x one. Setup: M2, macOS 27.0.1, ROS 2 from the Homebrew tap
Mixed versions behave as described in the PR description, on both versions:
Two observations:
Humble (2.6.x) needs a small context change to apply (no Scripts and full results: https://github.com/idesign0/ros2-macos-rmw-bench |
1 task done
idesign0
pushed a commit
to idesign0/id_Fast-DDS
that referenced
this pull request
Nov 20, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Maurice <mauricepurnawan@gmail.com> (cherry picked from commit 4a85ed4) Carried in id_Fast-DDS until eProsima#6632 is merged and backported (fixes eProsima#6639). Tested on macOS 27.0.1 (M2) against the ros2-kilted keg (Homebrew tap idesign0/ros2): built v3.2.5 + eProsima#6632 as libfastdds 3.2.5 Release with the keg's config.hpp (HAVE_SECURITY 0) and swapped it in via DYLD_LIBRARY_PATH. Unpatched build: 2 kHz Float64 KEEP_LAST 1 received 1074-1333 Hz at 2.3-2.5 ms p50, KEEP_LAST 100 p50 2.81 ms with 5.7 ms bursts. With eProsima#6632: 1814-1984 Hz at ~100 us p50, KEEP_LAST 100 p50 35 us with steady 0.5 ms arrival gaps; idle listener CPU 1.15 s -> 0.38 s per 20 s.
idesign0
pushed a commit
to idesign0/id_Fast-DDS
that referenced
this pull request
Nov 20, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Maurice <mauricepurnawan@gmail.com> (cherry picked from commit 4a85ed4) Carried in id_Fast-DDS until eProsima#6632 is merged and backported (fixes eProsima#6639). Tested on macOS 27.0.1 (M2) against the ros2-jazzy keg (Homebrew tap idesign0/ros2): built this branch + eProsima#6632 as libfastrtps 2.14.7 Release with the keg's config.h (HAVE_SECURITY 0, FASTDDS_STATISTICS) and swapped it in via DYLD_LIBRARY_PATH. Unpatched build: 2 kHz Float64 KEEP_LAST 1 received 1100-1135 Hz at 3.3 ms p50, KEEP_LAST 100 p50 2.86 ms with 5.7 ms bursts. With eProsima#6632: 1906-2158 Hz at 0.60-0.67 ms p50, KEEP_LAST 100 p50 36 us with steady 0.5 ms arrival gaps; idle listener CPU 1.13 s -> 0.32 s per 20 s.
idesign0
pushed a commit
to idesign0/id_Fast-DDS
that referenced
this pull request
Nov 22, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Maurice <mauricepurnawan@gmail.com> (cherry picked from commit 4a85ed4) Carried in id_Fast-DDS until eProsima#6632 is merged and backported (fixes eProsima#6639). Tested on macOS 27.0.1 (M2) against the ros2-jazzy keg (Homebrew tap idesign0/ros2): built this branch + eProsima#6632 as libfastrtps 2.14.7 Release with the keg's config.h (HAVE_SECURITY 0, FASTDDS_STATISTICS) and swapped it in via DYLD_LIBRARY_PATH. Unpatched build: 2 kHz Float64 KEEP_LAST 1 received 1100-1135 Hz at 3.3 ms p50, KEEP_LAST 100 p50 2.86 ms with 5.7 ms bursts. With eProsima#6632: 1906-2158 Hz at 0.60-0.67 ms p50, KEEP_LAST 100 p50 36 us with steady 0.5 ms arrival gaps; idle listener CPU 1.13 s -> 0.32 s per 20 s.
idesign0
pushed a commit
to idesign0/id_Fast-DDS
that referenced
this pull request
Nov 22, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Maurice <mauricepurnawan@gmail.com> (cherry picked from commit 4a85ed4) Carried in id_Fast-DDS until eProsima#6632 is merged and backported (fixes eProsima#6639). Tested on macOS 27.0.1 (M2) against the ros2-kilted keg (Homebrew tap idesign0/ros2): built v3.2.5 + eProsima#6632 as libfastdds 3.2.5 Release with the keg's config.hpp (HAVE_SECURITY 0) and swapped it in via DYLD_LIBRARY_PATH. Unpatched build: 2 kHz Float64 KEEP_LAST 1 received 1074-1333 Hz at 2.3-2.5 ms p50, KEEP_LAST 100 p50 2.81 ms with 5.7 ms bursts. With eProsima#6632: 1814-1984 Hz at ~100 us p50, KEEP_LAST 100 p50 35 us with steady 0.5 ms arrival gaps; idle listener CPU 1.15 s -> 0.38 s per 20 s.
idesign0
pushed a commit
to idesign0/id_Fast-DDS
that referenced
this pull request
Nov 29, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Maurice <mauricepurnawan@gmail.com> (cherry picked from commit 4a85ed4) Carried in id_Fast-DDS until eProsima#6632 is merged and backported (fixes eProsima#6639). Tested on macOS 27.0.1 (M2) against the ros2-jazzy keg (Homebrew tap idesign0/ros2): built this branch + eProsima#6632 as libfastrtps 2.14.7 Release with the keg's config.h (HAVE_SECURITY 0, FASTDDS_STATISTICS) and swapped it in via DYLD_LIBRARY_PATH. Unpatched build: 2 kHz Float64 KEEP_LAST 1 received 1100-1135 Hz at 3.3 ms p50, KEEP_LAST 100 p50 2.86 ms with 5.7 ms bursts. With eProsima#6632: 1906-2158 Hz at 0.60-0.67 ms p50, KEEP_LAST 100 p50 36 us with steady 0.5 ms arrival gaps; idle listener CPU 1.13 s -> 0.32 s per 20 s.
idesign0
pushed a commit
to idesign0/id_Fast-DDS
that referenced
this pull request
Nov 29, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Maurice <mauricepurnawan@gmail.com> (cherry picked from commit 4a85ed4) Carried in id_Fast-DDS until eProsima#6632 is merged and backported (fixes eProsima#6639). Tested on macOS 27.0.1 (M2) against the ros2-kilted keg (Homebrew tap idesign0/ros2): built v3.2.5 + eProsima#6632 as libfastdds 3.2.5 Release with the keg's config.hpp (HAVE_SECURITY 0) and swapped it in via DYLD_LIBRARY_PATH. Unpatched build: 2 kHz Float64 KEEP_LAST 1 received 1074-1333 Hz at 2.3-2.5 ms p50, KEEP_LAST 100 p50 2.81 ms with 5.7 ms bursts. With eProsima#6632: 1814-1984 Hz at ~100 us p50, KEEP_LAST 100 p50 35 us with steady 0.5 ms arrival gaps; idle listener CPU 1.15 s -> 0.38 s per 20 s.
idesign0
pushed a commit
to idesign0/id_Fast-DDS
that referenced
this pull request
Dec 4, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Maurice <mauricepurnawan@gmail.com> (cherry picked from commit 4a85ed4) Carried in id_Fast-DDS until eProsima#6632 is merged and backported (fixes eProsima#6639). Tested on macOS 27.0.1 (M2) against the ros2-kilted keg (Homebrew tap idesign0/ros2): built v3.2.5 + eProsima#6632 as libfastdds 3.2.5 Release with the keg's config.hpp (HAVE_SECURITY 0) and swapped it in via DYLD_LIBRARY_PATH. Unpatched build: 2 kHz Float64 KEEP_LAST 1 received 1074-1333 Hz at 2.3-2.5 ms p50, KEEP_LAST 100 p50 2.81 ms with 5.7 ms bursts. With eProsima#6632: 1814-1984 Hz at ~100 us p50, KEEP_LAST 100 p50 35 us with steady 0.5 ms arrival gaps; idle listener CPU 1.15 s -> 0.38 s per 20 s. (cherry picked from commit 956924d)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On macOS, Boost.Interprocess cannot use process-shared unnamed POSIX semaphores (
sem_initreturnsENOSYS), soboost::interprocess::interprocess_semaphorefalls back to its spin emulation. A waiting thread spins, yields, and then sleeps withthread_sleep_tick()between polls. The SHM transport waits on these semaphores insideRobustInterprocessCondition, so every SHM notification on macOS is delivered with a delay of up to a scheduler tick. The listener threads also keep waking while idle (the CPU cost reported in #2237). This is still the case in the latest Boost.This PR adds
RobustInterprocessSemaphore, used only on macOS in place ofinterprocess_semaphoreinRobustInterprocessCondition::SemaphoreNode:spin_semaphore.os_sync_wait_on_address(..., OS_SYNC_WAIT_ON_ADDRESS_SHARED), andpost()wakes a waiter withos_sync_wake_by_address_any. On older macOS it falls back to Boost'sspin_wait, which is the current behaviour.spin_semaphore, which only increments the counter and never wakes the waiter. With the cap, mixed-version setups are never slower than today.Other platforms are unchanged.
Results on macOS (Apple Silicon, macOS 27.2, Fast DDS 3.6.2 with and without this change, built from source with identical flags). 10 kHz, 192 B messages, KeepLast 1000, 8 s, SHM transport, 8 runs per build interleaved before/after:
Mixed versions: an old publisher with a new subscriber gives 100% delivery at 0.8 ms average latency. A new publisher with an old subscriber gives 100% at 3.3 ms, the same as today. For reference, the same benchmark on Linux, where this change compiles to nothing, gives 0.0 ms and almost no gaps.
@Mergifyio backport 3.2.x
Contributor Checklist
SharedMemTestsexercise the new code path and pass on macOS with this change.versions.mdfile (if applicable).Reviewer Checklist