Differences between ros::Duration::sleep and std::this_thread::sleep_for?
My team is developing in modern C++ and this is my first major project using ROS, but not my first major project using modern C++. I generally prefer using standard library functions to third party library functions, and so I generally use std::this_thread::sleep_for
in order to sleep the current thread context. This is different from much of the existing codebase which uses ROS's ros::Duration::sleep
and similar methods. I've looked through the source a little bit, but can't seem to find the actual implementation of ROS's sleep method.
Is there a difference between the implementations of these two methods I should be aware of? If not, have many developers stopped using ros::Duration in favor of standard functions?
Implementation is here: https://github.com/ros/roscpp_core/bl...
One thing to keep in mind IIRC is that ROS's
Time
andDuration
classes and associated methods take into account simulated time if you're running in a sim or using a bag file which standard library functions won't take into account@jayess: I think your comment is the answer, and I suggest reposting it as an answer
@VictorLamoine: +1 for the code reference, but please use permalinks. Otherwise future readers could be directed to completely unrelated lines due to code refactoring, addition, etc.
I've updated the link to be a permalink.