ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS multi thread c++

asked 2014-08-28 19:47:56 -0500

pjnsoo gravatar image

updated 2014-08-29 02:03:20 -0500

I developed two separate program and tested them. One program is for socket communication with external network the other one is for internal ros work. But then I add the first program as thread into ROS package and run the program I get this error:

Error message is that "malloc.c:2451: sYSMALLOc: Assertion '(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1)*2])) -
__builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0)"

I couldn't find any solution on the internet. Here is my source code and I omitted some not important parts. By removing line by lime I localized that the cause of error is in this line "SocketAddress sa(IPAddress(), 50000);". The error though appear right at the beginning of the program so I can really debug it. I guess the error is related to stack memory.

please help me.


using namespace std;
using namespace Poco::XML;
using namespace Poco::Net;
namespace enc = sensor_msgs::image_encodings;


AutoPtr<Document> pDoc;
sensor_msgs::CameraInfo info_cam;
std::vector<cv::Point> platform_corners(NUMBER_OF_CORNERS);
image_transport::Publisher pub_cropped;

class HelloRunnable: public Poco::Runnable{
    virtual void run(){
            SocketAddress sa(IPAddress(), 50000);
                DatagramSocket sock(sa);
                           //other code
    }
};
}

int main (int argc, char** argv){
    int i = 0;
    HelloRunnable runnable;
        Poco::Thread thread;
        thread.start(runnable);
        thread.join();
    ros::init (argc, argv, "locateCamera");
    ros::NodeHandle nh;
    boost::shared_ptr<image_transport::ImageTransport> it_(boost::shared_ptr<image_transport::ImageTransport>(new image_transport::ImageTransport(nh)));

    ros::Subscriber sub = nh.subscribe ("/ar_pose_marker", 1, &getCornersInPixCB);
    ros::Subscriber sub_info_l = nh.subscribe("/camera/camera_info", 1, &getCamInfoCb);

    ros::spin ();
}
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-08-29 13:18:02 -0500

tfoote gravatar image

It's likely that you're corrupting your memory. See here: https://stackoverflow.com/questions/2...

When running standalone you may be getting luck that the memory being corupted is less critical. As linked I suggest you use valgrind and make a minimal example to isolate your problem.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-08-28 19:47:56 -0500

Seen: 1,545 times

Last updated: Aug 29 '14