I have a Runnable
class (C++) which implements run()
method and it this method, I have an infinite loop which sends a message over a connection (this is not important).
However, it sends the messages too fast and this is totally unnecessary, thus I introduced a sleep function this_thread::sleep_for(chrono::milliseconds(10000));
and I expect this to slow down the speed, however it did not matter, it still sends fast as hell.
I am using ROS and ActiveMQ at the same time, these two introduce their own threads (I think) and this is the cause of the problem in my case I believe. Here is the piece of code in the main which does the whole thing:
// Start the producer thread.
Thread producerThread(&producer);
image_transport::Subscriber sub = it.subscribe("/uwsim/camera1", 1, imageCallback); // do the whole iamge processing
producerThread.start(); // pass the vision data! run() function is here initiated!
this_thread::sleep_for(chrono::milliseconds(10000)); //sleep a bit? does not work..
ros::spin();
// Wait for the threads to complete.
producerThread.join();
producer.close();
Why do you think my sleep function is not working? Do you think I placed it in the wrong line? Any idea?
Aucun commentaire:
Enregistrer un commentaire