diff options
| author | Corey Farwell <coreyf@rwell.org> | 2017-05-05 17:35:25 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-05 17:35:25 -0400 |
| commit | 69f4e318a0280d3cffda9fd9ca60ba084c5a27fd (patch) | |
| tree | 684d5a1c4abf59774166e9d31e8f7463088ffa7b /src/test/incremental/thinlto | |
| parent | 31a4d73e735ed0f9dceca3e44d4d46016efb13d0 (diff) | |
| parent | 495c998508039764b07a64303ae2c9461ec86a7b (diff) | |
| download | rust-69f4e318a0280d3cffda9fd9ca60ba084c5a27fd.tar.gz rust-69f4e318a0280d3cffda9fd9ca60ba084c5a27fd.zip | |
Rollup merge of #41512 - alexcrichton:fix-windows-tls-deadlock, 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
Diffstat (limited to 'src/test/incremental/thinlto')
0 files changed, 0 insertions, 0 deletions
