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 pthreadcondtimedwait 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) { pthreadcreate(&(this->pt1), NULL,recieve_packet,NULL); // Interferes with UDP in pose2sim plugin in gazebo this->flag=0; } else { mywait(10); }
pthreadmutext fakeMutex = PTHREADMUTEXINITIALIZER; pthreadcondt fakeCond = PTHREADCONDINITIALIZER;
void mywait(int timeInMs) { struct timespec timeToWait; struct timeval now; int rt; gettimeofday(&now,NULL); timeToWait.tvsec = now.tvsec+5; timeToWait.tvnsec = (now.tvusec+1000ULtimeInMs)1000UL; pthreadmutexlock(&fakeMutex); rt = pthreadcondtimedwait(&fakeCond, &fakeMutex, &timeToWait); pthreadmutexunlock(&fakeMutex); printf("\nDone\n"); }
Asked by pchidamb on 2020-03-12 13:15:18 UTC
Comments