Drop Pool job_sender explicitly using ManuallyDrop #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closing the channel is what allows the threads to shut down gracefully. Therefore, we want to drop the
job_sender
(closing the channel) before the threads are joined.That was already being accomplished by having
job_sender
as anOption
, and setting it toNone
in the destructor, which caused it to be explicitly dropped before the rest of the struct.The
std::mem::ManuallyDrop
wrapper, stabilized in Rust v1.20.0, was introduced to be a more performant and ergonomic way to explicitly drop in an arbitrary order.Alternatively, the correct drop order could also be accomplished implicitly, by changing the order in which the
Pool
struct fields are declared. However, the previous solution was an explicit one, so this change preserves that.