-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
sync: add sender_weak_count and sender_strong_count for Receiver #6661
sync: add sender_weak_count and sender_strong_count for Receiver #6661
Conversation
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.
🔢 Self-check (PR reviewed by myself and ready for feedback.)
} | ||
|
||
pub(super) fn weak_count(&self) -> usize { | ||
self.inner.tx_weak_count.load(Relaxed) |
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.
Why Relaxed here? Wouldn't Acquire be appropriate?
(I am curious, not saying you're wrong)
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.
It looks like this is just mirroring the orderings on the equivalent sender methods. I don't think it really matters.
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.
The main difference between them as I understand it is that with tx_weak_count, it's simply a counter. So it doesn't matter what order it's in.
But with tx_count we rely on it to decide whether to close the channel or not, in addition to counting the number, and it's more of a synchronized operation, where we have to make sure that there is a guaranteed ordering of operations on it between threads.
I'm not sure if I'm right about this, I could be completely wrong 😆
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
cace970
to
954858c
Compare
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.
LGTM. Thanks!
Motivation
close #6653
Solution
Added
sender_weak_count
andsender_strong_count
for Receiver and UnboundedReceiver.