Drop Pool job_sender explicitly using ManuallyDrop#21
Open
flpcury wants to merge 1 commit intoKimundi:masterfrom
Open
Drop Pool job_sender explicitly using ManuallyDrop#21flpcury wants to merge 1 commit intoKimundi:masterfrom
flpcury wants to merge 1 commit intoKimundi:masterfrom
Conversation
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 an Option, and setting it to None 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_senderas anOption, and setting it toNonein the destructor, which caused it to be explicitly dropped before the rest of the struct.The
std::mem::ManuallyDropwrapper, 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
Poolstruct fields are declared. However, the previous solution was an explicit one, so this change preserves that.