Skip to content

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