Fix mpsc::SyncSender spinning behavior by ibraheemdev · Pull Request #106701 · rust-lang/rust (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation7 Commits3 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

ibraheemdev

@ibraheemdev

@rustbot

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.

labels

Jan 11, 2023

@rustbot

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

@ibraheemdev

taiki-e

Member

@taiki-e taiki-e left a comment • Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK std::sync::mpmc does not use is_completed together with snooze, so this looks like the correct fix for the current implementation of std::sync::mpmc.

Resolves #106668.

I think beta backport is also needed to completely fix #106668 because it marked as regression-from-stable-to-beta.

@taiki-e

The current documentation around Backoff seems to be inconsistent with how it is actually used in the mpmc implementation, so (if we keep the current behavior) I would suggest updating it.

/// Backs off in a lock-free loop.
///
/// This method should be used when we need to retry an operation because another thread made
/// progress.
/// Backs off in a blocking loop.

@ibraheemdev

@Amanieu

I reviewed the current usage and think it is fine.

@bors r+

Separately, I think the retry loop when sending a message should be removed (like we did with the similar loop in recv). The reasoning is the same: we don't want to waste CPU cycles spinning when trying to write to a full channel. Instead we should just go ahead and block immediately. But this can be a separate PR.

@bors

📌 Commit 8917e99 has been approved by Amanieu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

and removed S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

labels

Jan 13, 2023

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Jan 13, 2023

@matthiaskrgr

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Jan 13, 2023

@matthiaskrgr

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jan 13, 2023

@bors

…iaskrgr

Rollup of 10 pull requests

Successful merges:

Failed merges:

r? @ghost @rustbot modify labels: rollup

@ibraheemdev

Separately, I think the retry loop when sending a message should be removed (like we did with the similar loop in recv). The reasoning is the same: we don't want to waste CPU cycles spinning when trying to write to a full channel. Instead we should just go ahead and block immediately. But this can be a separate PR.

I agree, the original reasoning was that it is similar to acquiring a mutex, but the difference is that bounded channels are often used with heavy backpressure, so a quick unpark is often not expected.

bors added a commit to rust-lang-ci/rust that referenced this pull request

Jan 20, 2023

@bors

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Jan 26, 2023

@matthiaskrgr

thomcc pushed a commit to tcdi/postgrestd that referenced this pull request

May 31, 2023

@matthiaskrgr

Labels

beta-accepted

Accepted for backporting to the compiler in the beta channel.

S-waiting-on-bors

Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.