Skip to content

Support shared futures on no_std - #2868

Merged
taiki-e merged 5 commits into
rust-lang:masterfrom
adavis628:master
Jan 16, 2025
Merged

taiki-e merged 5 commits into
rust-lang:masterfrom
adavis628:master

Conversation

@adavis628

Copy link
Copy Markdown
Contributor

Currently, Shared futures are only available when the std feature is enabled because they use std::sync::Mutex internally. This PR changes this so that Shared futures will fall back to using a spinlock when std is not enabled.

Alternatively, Shared could be changed to be generic over a mutex trait (e.g. lock_api::RawMutex, though it isn't implemented for std::sync::Mutex) to allow arbitrary user implementations.

@taiki-e

taiki-e commented Oct 2, 2024

Copy link
Copy Markdown
Member

Thanks for the PR. I would prefer not to use spinlock by default around operations that would involve allocations even if it is no_std-only.

That said, it might be fine if this is an optional feature and spinlock is used only when std is disabled and the feature is explicitly enabled.

@taiki-e taiki-e added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author A-future Area: futures::future labels Oct 2, 2024
@adavis628

Copy link
Copy Markdown
Contributor Author

I moved the spinlock behind an optional spin feature that will use a spinlock when std is disabled.

Comment thread futures-util/Cargo.toml Outdated
Comment thread futures-util/src/future/future/mod.rs Outdated

@taiki-e taiki-e left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@taiki-e taiki-e added 0.3-backport: pending The maintainer accepted to backport this to the 0.3 branch, but backport has not been done yet. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author labels Jan 16, 2025
@taiki-e
taiki-e merged commit 951d353 into rust-lang:master Jan 16, 2025
taiki-e pushed a commit that referenced this pull request Feb 15, 2026
@taiki-e taiki-e mentioned this pull request Feb 15, 2026
@taiki-e taiki-e added 0.3-backport: completed and removed 0.3-backport: pending The maintainer accepted to backport this to the 0.3 branch, but backport has not been done yet. labels Feb 15, 2026
taiki-e pushed a commit that referenced this pull request Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants