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

Implement joining_thread #808

Closed
wants to merge 2 commits into from
Closed

Conversation

kuzkry
Copy link
Contributor

@kuzkry kuzkry commented Sep 15, 2019

Note that this is rebased on top of #807 but it consists of one commit only (therefore I suggest going to the commit section and simplifying your review this way).

This PR implements a simple version of joining_thread. Appropriate thread library is detected and supplied by CMake.
Reasons why joining_thread derives privately from std::thread:

  • basically private inheritance works like composition with different semantics
  • it allows to get bunch of usings instead of redefining the whole std::thread interface
  • no problems with undefined behaviour if a user would try to delete joining_thread through the base class pointer
  • prevention of doing tricks, such as:
    joining_thread a([]{});
    a.detach() // compile error, detach() is deleted
    a.std::thread::detach(); // no error, though a loophole

Last but not least, I didn't care much about exceptions thrown by joinable(), I assumed it would have to be an incredibly crazy scenario for this function to throw, but noexcept(false) could theoretically be added there. I say "theoretically", because the same function is called by the destructor of std::thread anyway which would terminate in this case.

@kuzkry kuzkry force-pushed the joining_thread branch 2 times, most recently from aa49904 to 2dc74f6 Compare September 15, 2019 22:03
@kuzkry
Copy link
Contributor Author

kuzkry commented Sep 20, 2019

My bad, I didn't notice another pull request that tries to merge the same thing.

@kuzkry kuzkry closed this Sep 20, 2019
@kuzkry kuzkry deleted the joining_thread branch September 22, 2019 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant