Skip to content
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

Rollup of 8 pull requests #41759

Closed
wants to merge 14 commits into from
Closed

Rollup of 8 pull requests #41759

wants to merge 14 commits into from

Conversation

alexcrichton and others added 8 commits April 25, 2017 10:11
Gecko recently had a bug reported [1] with a deadlock in the Rust TLS
implementation for Windows. TLS destructors are implemented in a sort of ad-hoc
fashion on Windows as it doesn't natively support destructors for TLS keys. To
work around this the runtime manages a list of TLS destructors and registers a
hook to get run whenever a thread exits. When a thread exits it takes a look at
the list and runs all destructors.

Unfortunately it turns out that there's a lock which is held when our "at thread
exit" callback is run. The callback then attempts to acquire a lock protecting
the list of TLS destructors. Elsewhere in the codebase while we hold a lock over
the TLS destructors we try to acquire the same lock held first before our
special callback is run. And as a result, deadlock!

This commit sidesteps the issue with a few small refactorings:

* Removed support for destroying a TLS key on Windows. We don't actually ever
  exercise this as a public-facing API, and it's only used during `lazy_init`
  during racy situations. To handle that we just synchronize `lazy_init`
  globally on Windows so we never have to call `destroy`.

* With no need to support removal the global synchronized `Vec` was tranformed
  to a lock-free linked list. With the removal of locks this means that
  iteration no long requires a lock and as such we won't run into the deadlock
  problem mentioned above.

Note that it's still a general problem that you have to be extra super careful
in TLS destructors. For example no code which runs a TLS destructor on Windows
can call back into the Windows API to do a dynamic library lookup. Unfortunately
I don't know of a great way around that, but this at least fixes the immediate
problem that Gecko was seeing which is that with "well behaved" destructors the
system would still deadlock!

[1]: https://bugzilla.mozilla.org/show_bug.cgi?id=1358151
The bound is not required for compiling but it prevents using `next_token()` from a trait object.

Fixes rust-lang#33506.
First deprecated in rustc 1.8.0 the intention was to never allow `-Z` flags make
their way to the stable channel (or unstable options). After a year of warnings
we've seen one of the main use cases, `-Z no-trans`, stabilized as `cargo
check`. Otherwise while other use cases remain the sentiment is that now's the
time to start forbidding `-Z` by default on stable/beta.

Closes rust-lang#31847
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@frewsxcv
Copy link
Member Author

frewsxcv commented May 4, 2017

@bors r+ p=10

@bors
Copy link
Contributor

bors commented May 4, 2017

📌 Commit 5a8ad54 has been approved by frewsxcv

@bors
Copy link
Contributor

bors commented May 4, 2017

⌛ Testing commit 5a8ad54 with merge e174017...

@bors
Copy link
Contributor

bors commented May 4, 2017

💔 Test failed - status-appveyor

…ck, r=BurntSushi

std: Avoid locks during TLS destruction on Windows

Gecko recently had a bug reported [1] with a deadlock in the Rust TLS
implementation for Windows. TLS destructors are implemented in a sort of ad-hoc
fashion on Windows as it doesn't natively support destructors for TLS keys. To
work around this the runtime manages a list of TLS destructors and registers a
hook to get run whenever a thread exits. When a thread exits it takes a look at
the list and runs all destructors.

Unfortunately it turns out that there's a lock which is held when our "at thread
exit" callback is run. The callback then attempts to acquire a lock protecting
the list of TLS destructors. Elsewhere in the codebase while we hold a lock over
the TLS destructors we try to acquire the same lock held first before our
special callback is run. And as a result, deadlock!

This commit sidesteps the issue with a few small refactorings:

* Removed support for destroying a TLS key on Windows. We don't actually ever
  exercise this as a public-facing API, and it's only used during `lazy_init`
  during racy situations. To handle that we just synchronize `lazy_init`
  globally on Windows so we never have to call `destroy`.

* With no need to support removal the global synchronized `Vec` was tranformed
  to a lock-free linked list. With the removal of locks this means that
  iteration no long requires a lock and as such we won't run into the deadlock
  problem mentioned above.

Note that it's still a general problem that you have to be extra super careful
in TLS destructors. For example no code which runs a TLS destructor on Windows
can call back into the Windows API to do a dynamic library lookup. Unfortunately
I don't know of a great way around that, but this at least fixes the immediate
problem that Gecko was seeing which is that with "well behaved" destructors the
system would still deadlock!

[1]: https://bugzilla.mozilla.org/show_bug.cgi?id=1358151
join method returns a thread::Result

Join method returns a std::thread::Result, not a std::result::Result: https://doc.rust-lang.org/std/thread/struct.JoinHandle.html#method.join Maybe I misunderstood something.

I have seen this mistake(?) because I wanted to tackle this issue rust-lang#29378 (about Result). It's still one of my first PR. Sorry if I missed something.
Remove use of `Self: Sized` from libsyntax

The bound is not required for compiling but it prevents using `next_token()` from a trait object.

Fixes rust-lang#33506.
…uillaumeGomez

Simplify types in `std::option` doc comment example.

None
rustc: Forbid `-Z` flags on stable/beta channels

First deprecated in rustc 1.8.0 the intention was to never allow `-Z` flags make
their way to the stable channel (or unstable options). After a year of warnings
we've seen one of the main use cases, `-Z no-trans`, stabilized as `cargo
check`. Otherwise while other use cases remain the sentiment is that now's the
time to start forbidding `-Z` by default on stable/beta.

Closes rust-lang#31847
…, r=arielb1

kill some unused fields in TyCtxt
@frewsxcv frewsxcv closed this May 5, 2017
@Centril Centril added the rollup A PR which is a rollup label Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rollup A PR which is a rollup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants