Skip to content

Fix macOS compatibility issues in realtime_tools package - #370

Merged
saikishor merged 21 commits into
ros-controls:masterfrom
idesign0:master
Aug 7, 2025
Merged

saikishor merged 21 commits into
ros-controls:masterfrom
idesign0:master

Conversation

@idesign0

Copy link
Copy Markdown
Contributor

in source and cmakefile:

  • Enable successful compilation and runtime behavior of realtime_tools on macOS, enhancing cross-platform support.
  • Link against the atomic library on non-Windows platforms to resolve linker errors with clang.

in tests:

  • Fix missing pthread functions and constants on macOS (pthread_mutex_consistent, pthread_mutexattr_setrobust, PTHREAD_MUTEX_STALLED) using conditional compilation.
  • Adjust mutex robustness handling to be compatible with macOS pthread implementation.

thanks a lot @traversaro for the original patch that this PR builds upon to fix macOS compatibility issues.

@saikishor saikishor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@idesign0 You have some conflicts in the package currently. Please kindly fix them and push

Signed-off-by: Dhruv Patel <[email protected]>
Comment thread realtime_tools/CMakeLists.txt Resolved
Comment on lines +126 to +127
// On platforms like macOS, pthread_mutexattr_setrobust is not available,
// so skip this step

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a std::cerr like others?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, macOS doesn’t define pthread_mutexattr_setrobust or related constants like PTHREAD_MUTEX_STALLED in its system headers, so this conditional block was added to skip robustness configuration on that platform.
Suggestions or better cross-platform handling approaches are definitely welcome!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ofcourse, I was referrinf to that in certain places you left std::cerr. May be here it doesn't make sense

#else
std::cerr << "Mutex owner died, but pthread_mutex_consistent is not supported on this platform."
<< std::endl;
#endif

Co-authored-by: Sai Kishor Kothakota <[email protected]>
@traversaro

Copy link
Copy Markdown
Contributor

thanks a lot @traversaro for the original patch that this PR builds upon to fix macOS compatibility issues.

I guess the original patch from @Tobias-Fischer, but thanks a lot for taking the time of opening a PR with the fix!

@christophfroehlich christophfroehlich left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for improving this.
Is pre-commit available on mac? Please install it, as the checks are failing.

If you like you can also open a PR in adding a github workflow for MacOS support.

Comment thread realtime_tools/CMakeLists.txt Resolved
@idesign0

Copy link
Copy Markdown
Contributor Author

@christophfroehlich

Thanks! Yes, pre-commit is available on macOS — I’ll install it and run the checks again to fix the current issues.
Also, adding a GitHub workflow for macOS sounds like a great idea. I’ll look into it and open a separate PR for that.

Comment on lines +126 to +127
// On platforms like macOS, pthread_mutexattr_setrobust is not available,
// so skip this step

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ofcourse, I was referrinf to that in certain places you left std::cerr. May be here it doesn't make sense

#else
std::cerr << "Mutex owner died, but pthread_mutex_consistent is not supported on this platform."
<< std::endl;
#endif

Comment thread realtime_tools/src/realtime_helpers.cpp Resolved
Comment thread realtime_tools/src/realtime_helpers.cpp Resolved
Comment thread realtime_tools/src/realtime_helpers.cpp Resolved
Comment thread realtime_tools/src/realtime_helpers.cpp Resolved
Comment thread realtime_tools/src/realtime_helpers.cpp Resolved
@saikishor

Copy link
Copy Markdown
Member

@idesign0 Please check the codebase again to see if any other cleanup is needed

@idesign0

Copy link
Copy Markdown
Contributor Author

@saikishor @christophfroehlich

Hi, I noticed that the ament_cppcheck hook is failing with a message about limiting branch analysis, but no actual errors were found. All other checks are passing. Would it be okay to proceed despite this, or should I investigate further?

ament_cppcheck...........................................................Failed

  • hook id: ament_cppcheck
  • exit code: 1

[realtime_tools/src/realtime_helpers.cpp:0]: (information: normalCheckLevelMaxBranches) Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches.
1 errors
No problems found
No problems found
No problems found
No problems found

@idesign0

Copy link
Copy Markdown
Contributor Author

If anyone has insights into what might be going wrong in the CI environment, I’d really appreciate the input.

I tried in the ros:rolling docker container (on an ubuntu host), and it fails with the exact issue. On which linux distro have you tried it? native or in a docker container on MacOS host?

Hii, I'm running Ubuntu 22.04.5 LTS (Jammy) inside Parallels on a macOS host — no Docker involved. I'm using ROS 2 Humble with backported changes of package.

@christophfroehlich

Copy link
Copy Markdown
Member

I don't think that this is a ROS package issue. can you try with an ubuntu noble docker inside your VM? ros:rolling for example..

@idesign0

Copy link
Copy Markdown
Contributor Author

I don't think that this is a ROS package issue. can you try with an ubuntu noble docker inside your VM? ros:rolling for example..

Ok. I’ll run the test in a Noble container and follow up once I have results.

@idesign0

idesign0 commented Jul 29, 2025 •

Copy link
Copy Markdown
Contributor Author

@christophfroehlich @saikishor

I’ve tested the build in a Docker container with ROS Rolling. The realtime_tools package compiles successfully, but one of the CTests—specifically the 8th one (the same), lock_unlock_multithreaded_mutex_one_thread_dies—is failing. I plan to trace the issue further using GDB to understand what’s going wrong. for time, i am not using noble container.

@idesign0

idesign0 commented Aug 1, 2025

Copy link
Copy Markdown
Contributor Author

@saikishor @christophfroehlich

All tests are passing now in ROS Rolling. :)

@codecov-commenter

codecov-commenter commented Aug 1, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.21%. Comparing base (ada7143) to head (f95643d).
⚠️ Report is 35 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #370   +/-   ##
=======================================
  Coverage   87.21%   87.21%           
=======================================
  Files          17       17           
  Lines        1291     1291           
  Branches      104      104           
=======================================
  Hits         1126     1126           
  Misses         97       97           
  Partials       68       68           
Flag Coverage Δ
unittests 87.21% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
realtime_tools/include/realtime_tools/mutex.hpp 44.64% <ø> (ø)
realtime_tools/src/realtime_helpers.cpp 38.61% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@christophfroehlich christophfroehlich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@saikishor saikishor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed these 2 in my initial review. Rest looks good

@saikishor saikishor added the backport-jazzy Triggers PR backport to ROS 2 jazzy. label Aug 7, 2025
@saikishor
saikishor merged commit d6b4113 into ros-controls:master Aug 7, 2025
mergify Bot pushed a commit that referenced this pull request Aug 7, 2025
---------

Signed-off-by: Dhruv Patel <[email protected]>
Co-authored-by: Sai Kishor Kothakota <[email protected]>
Co-authored-by: Christoph Fröhlich <[email protected]>
Co-authored-by: Copilot <[email protected]>
(cherry picked from commit d6b4113)
idesign0 added a commit to idesign0/id_realtime_tools that referenced this pull request Aug 7, 2025
…s#370)

---------

Signed-off-by: Dhruv Patel <[email protected]>
Co-authored-by: Sai Kishor Kothakota <[email protected]>
Co-authored-by: Christoph Fröhlich <[email protected]>
Co-authored-by: Copilot <[email protected]>
@christophfroehlich

Copy link
Copy Markdown
Member

@Mergifyio backport humble

@mergify

mergify Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

backport humble

✅ Backports have been created

Details

Cherry-pick of d6b4113 has failed:

On branch mergify/bp/humble/pr-370
Your branch is up to date with 'origin/humble'.

You are currently cherry-picking commit d6b4113.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   include/realtime_tools/mutex.hpp
	modified:   src/realtime_helpers.cpp

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   CMakeLists.txt

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

christophfroehlich added a commit that referenced this pull request Dec 1, 2026
…) (#658)

* Fix macOS compatibility issues in realtime_tools package (#370)

---------

Signed-off-by: Dhruv Patel <[email protected]>
Co-authored-by: Sai Kishor Kothakota <[email protected]>
Co-authored-by: Christoph Fröhlich <[email protected]>
Co-authored-by: Copilot <[email protected]>
(cherry picked from commit d6b4113)

# Conflicts:
#	CMakeLists.txt

* Resolve CMakeLists.txt conflicts of the humble backport

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Dhruv Patel <[email protected]>
Co-authored-by: Christoph Froehlich <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-jazzy Triggers PR backport to ROS 2 jazzy.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants