I have a function that shoud run in a controlled amount of time. But this function uses pcl::StatisticalOutlierRemoval
and i didn't find any reasonable way to cancel the this function other than killing the thread arbitrarily.
I have something like this:
void cloud_filtering(pcl::PointCloud<pcl::PointXYZRGB>::SharedPtr pcl_unfilt, pcl::PointCloud<pcl::PointXYZRGB>::SharedPtr pcl_filt) const{
// do something
pcl::StatisticalOutlierRemoval<pcl::PointXYZRGB> sor;
sor.setInputCloud(*pcl_unfilt);
sor.setMeanK(50);
sor.setStddevMulThresh(1.0);
sor.filter(*pcl_filt);
// do something
}
This function is executed by an independent thread that should have some timeout. The thread is launched using std::async and the completion is checked using the returned future.
auto future = std::async(
std::launch::async,
&cloud_filtering,this,pcl_unfilt,pcl_filt
)
Usually, this function is executed pretty fast, but not always, and I don't really need all the responses (It depends on the sampled input of the function). So what I want to do is, if the function takes more than a given timeout it gets safely canceled so I can launch a new thread with other samples.
By safely canceled I mean avoid memory leaks or zombie threads.