[ros-users] Nodelets and thread safety

Josh Faust jfaust at willowgarage.com
Mon Oct 25 17:44:54 UTC 2010


> Yes, exactly. i.e. sharing a large object between publisher and
> subscriber(s) and you want to avoid any copying or recreation of the object.
> The publisher is continually updating the large object and the subscribers
> don't want to get caught by an update in the middle of reading. Is there
> perhaps a better approach to this? How do the guys in the image pipeline
> handle the sending of big objects - they simply recreate a new object every
> time they want to send one?
>
>

If you actually want the subscribers reading from a shared store, I'd say
pub/sub is not really the way to go.  If you want each message to be able to
be processed by part of your pipeline (like with images, point clouds,
etc.), you need to allocate a new message for each set of new data.

That said, if you really wanted to do it that way, it's possible you could
write a templated wrapper class that you adapted as a ROS message, something
like:
template<typename M>
class MutexedMessage
{
  boost::mutex mutex;
  boost::shared_ptr<M const> msg;
};

If this was adapted as a roscpp message (
http://www.ros.org/wiki/roscpp/Overview/MessagesSerializationAndAdaptingTypes),
and you published/subscribed with shared_ptrs to it you'd get essentially
what you're asking.  I don't recommend it as a solution though.

Josh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ros.org/pipermail/ros-users/attachments/20101025/4c357b49/attachment-0003.html>


More information about the ros-users mailing list