← Back to Pull requests

Use os_sync_wait_on_address for SHM condition semaphores on macOS #6632

Open
unknown opened this pull request with 522 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 15, 2026 17:20 UTC
Author

Description

On macOS, Boost.Interprocess cannot use process-shared unnamed POSIX semaphores (sem_init returns ENOSYS), so boost::interprocess::interprocess_semaphore falls back to its spin emulation. A waiting thread spins, yields, and then sleeps with thread_sleep_tick() between polls. The SHM transport waits on these semaphores inside RobustInterprocessCondition, 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 of interprocess_semaphore in RobustInterprocessCondition::SemaphoreNode:

  • It is a 32-bit atomic counter in shared memory, the same layout as Boost's spin_semaphore.

  • On macOS 14.4+ it blocks in the kernel with os_sync_wait_on_address(..., OS_SYNC_WAIT_ON_ADDRESS_SHARED), and post() wakes a waiter with os_sync_wake_by_address_any. On older macOS it falls back to Boost's spin_wait, which is the current behaviour.

  • Each kernel wait is capped at 1 ms. Processes running an older Fast DDS post through Boost's 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:

    | | before | after |
    |---|---|---|
    | average latency (median) | 3.3 ms (3.2–7.1) | 0.3 ms (0.2–0.5) |
    | inter-arrival gaps > 1 ms | 1,160–1,247 | 167–264 |
    | subscriber CPU at 10 kHz | 19–21% | 26–30% (wake per message instead of batched polling) |
    | idle subscriber CPU, 4 runs | 1.0–1.1 s / 20 s | 0.42–0.43 s / 20 s |

    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

    <!--
    - If any of the elements of the following checklist is not applicable, substitute the checkbox [ ] by _N/A_:
    - If any of the elements of the following checklist is not fulfilled on purpose, please provide a reason and substitute the checkbox [ ] with ❌: or __NO__:.
    -->

  • Commit messages follow the project guidelines.

  • The code follows the style guidelines of this project. Written to match the surrounding code (uncrustify was not run locally).

  • __NO__: Tests that thoroughly check the new feature have been added/Regression tests checking the bug and its fix have been added; the added tests pass locally. This is a latency/CPU fix with no functional change, so there is nothing to assert in a unit test. The existing SharedMemTests exercise the new code path and pass on macOS with this change.

  • Any new/modified methods have been properly documented using Doxygen.

  • _N/A_ Any new configuration API has an equivalent XML API (with the corresponding XSD extension)

  • Changes are backport compatible: they do NOT break ABI nor change library core behavior. The new class is internal, and the shared-memory layout is unchanged.

  • Changes are API compatible.

  • _N/A_ New feature has been added to the versions.md file (if applicable).

  • _N/A_ New feature has been documented/Current behavior is correctly described in the documentation.

  • Applicable backports have been included in the description. The patch applies cleanly to 3.2.x.
  • Reviewer Checklist

  • The PR has a milestone assigned.

  • The title and description correctly express the PR's purpose.

  • Check contributor checklist is correct.

  • If this is a critical bug fix, backports to the critical-only supported branches have been requested.

  • Check CI results: changes do not issue any warning.

  • Check CI results: failing tests are unrelated with the changes.
  • Diff: 522 lines (+391 / -131) across 6 files Reviewer: mini-1235 Review duration: 21871m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.48) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 522 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.374
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #6632"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.8% (MEDIUM) · Higher = larger blast radius
    47.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.5% · Safe to merge
    25.5%