Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition from boost::thread to std::thread. #3060

Merged
merged 1 commit into from
May 7, 2019

Conversation

SergioRAgostinho
Copy link
Member

Just dumping this here to see if it compiles and if it looks ok for review.

@SergioRAgostinho SergioRAgostinho added needs: code review Specify why not closed/merged yet needs: author reply Specify why not closed/merged yet changelog: ABI break Meta-information for changelog generation and removed needs: author reply Specify why not closed/merged yet labels May 3, 2019
@SergioRAgostinho
Copy link
Member Author

If possible, give priority to this one. I have some other PRs pending on it.

Copy link
Member

@taketwo taketwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the ping, apparently I missed the point when this became ready.

@@ -566,7 +566,7 @@ pcl::HDLGrabber::stop ()
bool
pcl::HDLGrabber::isRunning () const
{
return (!hdl_data_.isEmpty () || (hdl_read_packet_thread_ != nullptr && !hdl_read_packet_thread_->timed_join (boost::posix_time::milliseconds (10))));
return (!hdl_data_.isEmpty () || hdl_read_packet_thread_);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you help me to understand what was the point of timed_join and why we don't need it anymore? (I do know that std::thread does not have it, but still.)

Copy link
Member Author

@SergioRAgostinho SergioRAgostinho May 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, indeed we're missing some logic if we just remove everything.

The underlying logic with timed_join was the following: you request the thread to join under a specified time and if it manages to successfully do it, it returns true, otherwise false. If your grabber is running normally, there´s no chance for the thread to join, hence the check for that condition. As you said, we no longer have access to timed_join, but usually all these grabbers have an exit flag - terminate_read_packet_thread_ in this case - which marks the intent to break out of the grabber loop. This exit flag is not a real/pure proxy to check if the grabber is still running or not, but it gives you an indication of what will happen very soon, making it a potentially viable replacement candidate to check. Ultimately, I can have a look on how to fully replace this functionality with a condition_variable. It might actually not be super involved.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. With this PR there will be a brief period between stop() is called and the thread has joined during which isRunning() will still return true. I don't think this is a problem. Technically, we are still grabbing if the thread hasn't joined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this PR there will be a brief period between stop() is called and the thread has joined during which isRunning() will still return true.

To prevent that we can add a check to terminate_read_packet_thread_. This is the first variable to get set to true once stop() is invoked. I see no harm in doing it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, but setting that flag does not terminate the grabber thread right away. It may happen that one more frame is read before it has an effect.

Ultimately this comes down to the fact that we don't have a strict definition what "is running" means. Is it when the thread is still active? Is it until stop() is called? But I guess it's not that important. If you prefer, you can add the check you mentioned, then we will adopt the second definition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No preference. Since there's no strict definition and currently no reason to create one I say we could leave as it is.

@taketwo taketwo removed the needs: code review Specify why not closed/merged yet label May 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: ABI break Meta-information for changelog generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants