-
Notifications
You must be signed in to change notification settings - Fork 8
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
Match other implementations #6
Conversation
Hi! Thanks for your contribution, drop part looks good to me, but I think you are inaccurate about the fence part, as the std library under the hood is using: #[cfg(not(sanitize = "thread"))]
macro_rules! acquire {
($x:expr) => {
atomic::fence(Acquire)
};
}
#[cfg(sanitize = "thread")]
macro_rules! acquire {
($x:expr) => {
$x.load(Acquire)
};
} which actually is not loading in the standard build without the thread sanitizer, and is using |
Unfortunately According to rust-lang/rust#41714, as far as the actual counter is concerned it's basically equivalent, but they use a fence just in case there are other (possibly incorrectly used) nearby atomic things related to the inner data.
Perhaps |
Based on my understanding and knowledge of atomic operations, in our specific case of the "drop" operation, using If we unreasonably use atomic load, it will significantly impact the performance of the code because atomic loads are not cheap. According to the documentation in
In my opinion, the current implementation of the triomphe drop is not optimized, and there is no justification for us to replicate the same approach. |
Furthermore, I believe it would be more beneficial to avoid explicitly marking In general, I am opposed to compelling the compiler to avoid inlining something when we are uncertain if it is a sound strategy. |
I could do: if mem::needs_drop::<T>() {
self.drop_slow();
} so it never generates a call at all if the type doesn't need it. However, it's not like a function call is particularly expensive. And regarding the memory fence, you're probably right. Perhaps triomphe chose what it did because of the thread sanitizer limitations. |
Unfortunately, that will not be a sound approach as the code will leak memory because we need to drop the pointer to data and counter even if the type does not implement the Drop trait. Just remove the |
Oh, of course, my mistake. I had been thinking about how I did something very similar in |
No problem at all, it happens. |
There you go. Only real change now is pulling out the drop. |
Thanks, could you please edit your PR as a single commit with title like "Adding drop_slow to Drop trait implementation"? |
You should be able to squash commits from GitHub’s UI, as one of the modes of merging. |
Use a load specifically oncount
instead of afence
, this is what std and triomphe do.