Repository navigation
PR for Issue #471 Added Thread Classes: gsl::raii_thread gsl::detached_thread - #481
Galik (galik) wants to merge 7 commits into
Conversation
|
|
||
| std::thread::native_handle_type native_handle() { return t.native_handle(); } | ||
|
|
||
| void join() { t.join(); } |
There was a problem hiding this comment.
If the std::thread is actually detached, this will throw. I don't think there's a point in exposing a method that will always just throw no matter what.
| raii_thread& operator=(raii_thread const&) = delete; | ||
| raii_thread& operator=(raii_thread&& other) noexcept | ||
| { | ||
| t = std::move(other.t); |
There was a problem hiding this comment.
This std::terminates if this->t hasn't been joined. This isn't in the spirit of an RAII wrapper. It should likely first properly "reset" this and then move the rhs into it, similarly to what other RAII managers, like unique_ptr would do.
A check if (this != &rhs) on top of it would be needed too.
There was a problem hiding this comment.
When you say "reset" this do you mean perform a join()? Because I am not entirely sure about that.
I could be wrong but my feeling is that the main use for this function is when you are moving into a default initialized raii_thread. For example when returning a raii_thread from a function or accepting one as a parameter.
If the client actually assigns a raii_thread to an already running one then performing a join might introduce hidden, unexpected serialization delays and I suspect it would rarely be the intention to move a running raii_threadonto another already running one.
Would that not always be an error?
I am willing to be persuaded either way. I think I would generally rather it trigger a terminal error than silently join because (with an raii_thread) I would probably always want to do the join explicitly using the natural scope.
|
The main thing is to get I'm less positive about adding a Suggestion: Could we separate the PR into two so that we can adopt the |
|
See new PR #504 |
This PR adds <gsl/gsl_thread> and tests/thread_tests.cpp
Fixes for Issue #471
Notes:
I have copied the interface of
std::threadexcept forstd::thread::detach. The reason being thatgsl::detached_threadis already detached andgsl::raii_threadshould not be detached by design.