Document that destructors in running threads are not run on program exit#156788
Document that destructors in running threads are not run on program exit#156788jwodder wants to merge 1 commit into
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
r? lang Since this feels like more a lang decision than a libs decision. I also believe this is the case currently, but don't know if we have any other documentation that's relevant here, and whether this is desired as a guarantee. |
|
We talked about this in the lang call. We wanted to change the text to say "may", as @joshtriplett has now left a review comment about. After that's updated, one of us will |
|
@traviscross I've applied Josh's suggested wording change. |
|
Please squash. |
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
|
@traviscross Squashed. |
|
@bors r+ rollup |
|
Thanks @jwodder. |
|
Actually, this behavior is already documented elsewhere (mentioning this not as an argument against documenting it here, too, but to ensure consistency): In the documentation of
and later
and one more time even further below
|
That last line is a bit too buried for my liking, and the "returning from |
|
I wonder if it would be sufficient to instead just turn "shuts down" into a link to make the connection clear? This would also avoid the need for duplicate documentation of this detail.
Additionally on that page, I see
But the “preferable” way described there doesn’t actually ensure “no more destructors left to run” for you, in case there are other threads not being waited on; so maybe the
highlighting the “equivalent” phrasing too early could lead to misconceptions that they’re also equivalent for the purpose of handling local variables inside of main. The ambiguity that could cause this comes from the fact that “returning from main” may be understood as “the thing that happens after main has finished and has ran all local destructors” or “all effects of “evaluating” a |
…ross Document that destructors in running threads are not run on program exit It's my understanding that, when a Rust program's main thread terminates and thereby causes any still-running threads to be shut down, destructors are not run for the shut-down threads; however, the documentation doesn't seem to come out and say that explicitly anywhere. This PR therefore adds an explicit statement about this to the `std::thread` docs. If I am mistaken and destructors *are* run, that's worth documenting explicitly, too.
…uwer Rollup of 6 pull requests Successful merges: - #157816 (make more slice mutable ref getters rustc_no_writable) - #156788 (Document that destructors in running threads are not run on program exit) - #157957 (Add documentation for the `must_use` attribute) - #158006 (Simplify `HardwiredLints` and `SoftLints`) - #158007 (Pin dependencies) - #158025 (Enable `symbol_intern_string_literal` lint for rustdoc)
It's my understanding that, when a Rust program's main thread terminates and thereby causes any still-running threads to be shut down, destructors are not run for the shut-down threads; however, the documentation doesn't seem to come out and say that explicitly anywhere. This PR therefore adds an explicit statement about this to the
std::threaddocs.If I am mistaken and destructors are run, that's worth documenting explicitly, too.