Re: [ros-users] Nodelets and thread safety

Top Page
Attachments:
Message as email
+ (text/plain)
+ (text/html)
Delete this message
Reply to this message
Author: User discussions
Date:  
To: User discussions
Subject: Re: [ros-users] Nodelets and thread safety
> 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