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

Drop Pool job_sender explicitly using ManuallyDrop #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

flpcury
Copy link

@flpcury flpcury commented Feb 12, 2024

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.

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.
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.

1 participant