-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Document the behaviour of RUST_MIN_STACK=0 #135178
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
Open
Gankra
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
Gankra:patch-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -125,9 +125,12 @@ | |||||
//! ## Stack size | ||||||
//! | ||||||
//! The default stack size is platform-dependent and subject to change. | ||||||
//! Currently, it is 2 MiB on all Tier-1 platforms. | ||||||
//! Currently, it is 2 MiB on all Tier-1 platforms to make programs behave more consistently | ||||||
//! cross-platform (notably Windows would otherwise default to 1MiB stacks). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
//! | ||||||
//! There are two ways to manually specify the stack size for spawned threads: | ||||||
//! You can overload Rust's default stack size with one of the two following methods. | ||||||
//! Passing 0 to either of them will be treated as a request to instead use the | ||||||
//! platform's "normal" default stack size (e.g. reverting Windows back to 1MiB stacks). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
//! | ||||||
//! * Build the thread with [`Builder`] and pass the desired stack size to [`Builder::stack_size`]. | ||||||
//! * Set the `RUST_MIN_STACK` environment variable to an integer representing the desired stack | ||||||
|
@@ -495,7 +498,11 @@ impl Builder { | |||||
.unwrap_or(imp::DEFAULT_MIN_STACK_SIZE); | ||||||
|
||||||
// 0 is our sentinel value, so ensure that we'll never see 0 after | ||||||
// initialization has run | ||||||
// initialization has run even if RUST_MIN_STACK=0. | ||||||
// | ||||||
// Note that a stack size of 0 is actually a meaningful input, as each platform's | ||||||
// thread implementation is expected to use it as a signal to use the | ||||||
// platform's "normal" default thread size instead of Rust's preferred one. | ||||||
MIN.store(amt + 1, Ordering::Relaxed); | ||||||
amt | ||||||
}); | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hm, maybe this is a nitpick but the Windows comment isn't strictly accurate. The default size is linker-defined, which does (on MSVC at least) use 1MiB if not otherwise set but it can be different. So saying 0 means 1MiB on Windows is not necessarily true even now and in the future Rust might opt to use a different value by default.
That said, I'm not sure it's worth going on about
/stack
here, Maybe it's acceptable to say "1MiB" in a lies to children kind of way.Uh oh!
There was an error while loading. Please reload this page.
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.
Yeah that's basically the emotional arc I went through. I was sorely tempted to specify "usually" or something.
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.
Fair. I'm a little bit uncomfortable with std docs that aren't technically correct but it is truthish and it does make sense to mention the 1MiB somewhere as it's something that does trip up cross-platform code (admittedly mostly for the main thread rather than spawning new ones but still).
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 posted a couple of suggestions improving this to be more accurate. (The resulting comments need word-wrapping after applying the suggestions.)