-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add broadcast::Sender::len #5343
Conversation
The binary search can race with updates to |
while low < high { | ||
let mid = low + (high - low) / 2; | ||
let idx = base_idx.wrapping_add(mid) & self.shared.mask; | ||
if self.shared.buffer[idx].read().unwrap().rem.load(SeqCst) == 0 { |
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 think this can probably be a relaxed load rather than sequentially consistent, but haven't thought too carefully about it.
Ping! |
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.
Sorry about the delay. It looks correct, but its rather complicated, so I would like to see a more comprehensive test. Perhaps something that randomly chooses between "recv on chan 1, recv on chan 2, send a message" and checks that the length is correct between each iteration, for 1000 iterations?
Will do! |
Updated with a test that performs random operations and compares Sender::len against Receiver::len. |
Updated! |
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.
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [tokio](https://tokio.rs) ([source](https://github.com/tokio-rs/tokio)) | dependencies | minor | `1.24.2` -> `1.25.0` | | [tokio](https://tokio.rs) ([source](https://github.com/tokio-rs/tokio)) | dev-dependencies | minor | `1.24.2` -> `1.25.0` | --- ### Release Notes <details> <summary>tokio-rs/tokio</summary> ### [`v1.25.0`](https://github.com/tokio-rs/tokio/releases/tag/tokio-1.25.0): Tokio v1.25.0 ##### 1.25.0 (January 28, 2023) ##### Fixed - rt: fix runtime metrics reporting ([#​5330]) ##### Added - sync: add `broadcast::Sender::len` ([#​5343]) ##### Changed - fs: increase maximum read buffer size to 2MiB ([#​5397]) [#​5330]: tokio-rs/tokio#5330 [#​5343]: tokio-rs/tokio#5343 [#​5397]: tokio-rs/tokio#5397 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about these updates again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xMTYuMSIsInVwZGF0ZWRJblZlciI6IjM0LjExOS4yIn0=--> Co-authored-by: cabr2-bot <[email protected]> Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1761 Reviewed-by: crapStone <[email protected]> Co-authored-by: Calciumdibromid Bot <[email protected]> Co-committed-by: Calciumdibromid Bot <[email protected]>
Since the head index for each receiver isn't stored in a location accessible from the sender, we need to instead binary search for the last value with remaining readers.
Closes #5334