Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Creating a separate thread in rayplugin onscan function and moving controls between threads

I am able to use pthread and create a separate thread, however when I use pthread_cond_timedwait I am unable to consistently move to between the main thread - onscan and the thread function. Why is this?

void GazeboRosVelodyneLaser::OnScan(ConstLaserScanStampedPtr &_msg) { if (this->flag ==1) { pthread_create(&(this->pt1), NULL,recieve_packet,NULL); // Interferes with UDP in pose2sim plugin in gazebo this->flag=0; } else {


pthread_mutex_t fakeMutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t fakeCond = PTHREAD_COND_INITIALIZER;

void mywait(int timeInMs) { struct timespec timeToWait; struct timeval now; int rt;


timeToWait.tv_sec = now.tv_sec+5;
timeToWait.tv_nsec = (now.tv_usec+1000UL*timeInMs)*1000UL;

rt = pthread_cond_timedwait(&fakeCond, &fakeMutex, &timeToWait);