-
Notifications
You must be signed in to change notification settings - Fork 185
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
Fix memory leak of MpMcQueue
#483
Conversation
d1eac57
to
7cfdb84
Compare
impl<T, const N: usize> Drop for MpMcQueue<T, N> { | ||
fn drop(&mut self) { | ||
// drop all contents currently in the queue | ||
while self.dequeue().is_some() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is copying the elements to the stack before dropping them, and running the complex dequeue() logic.
it'd be more efficient to read enqueue_pos/dequeue_pos, iterate, then .assume_init_drop() all the items in place. No copies, no atomic ops. This is sound because on drop we have &mut self
so we know no other thread can be concurrently accessing the queue at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to implement that but I'm not 100% certain I understand the layout of the Queue which is not documented, and which items are actually valid. I'm certain that the dequeue
approach is correct so this is the approach I took.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, it's true it's not that trivial. We can optimize later if someone complains.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's open an Issue for that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
Fix #482