Repository: rust
Issue: Deadlock detected with parallel front-end in nightly
Labels: I-ICE,T-compiler,C-bug,WG-compiler-parallel,S-needs-repro

I have caught `deadlock detected` while building with `RUSTFLAGS="-Z threads=4"` in nightly.

### Code
Sorry, I cannot provide a minimal code example as I saw it only once on a big codebase.

### Meta
`rustc --version --verbose`:
```
rustc 1.80.1 (3f5fd8dd4 2024-08-06)
binary: rustc
commit-hash: 3f5fd8dd41153bc5fdca9427e9e05be2c767ba23
commit-date: 2024-08-06
host: x86_64-unknown-linux-gnu
release: 1.80.1
LLVM version: 18.1.7
```

### Error output

```
thread '<unnamed>' panicked at compiler/rustc_query_system/src/query/job.rs:543:9:
deadlock detected
...
error: could not compile `regex-syntax` (lib)

Caused by:
  process didn't exit successfully: `/home/ubuntu/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name regex_syntax --edition=2021 /home/ubuntu/.cargo/registry/src/index.crates.io-6f17d22bba15001f/regex-syntax-0.7.5/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=208 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="std"' --cfg 'feature="unicode"' --cfg 'feature="unicode-age"' --cfg 'feature="unicode-bool"' --cfg 'feature="unicode-case"' --cfg 'feature="unicode-gencat"' --cfg 'feature="unicode-perl"' --cfg 'feature="unicode-script"' --cfg 'feature="unicode-segment"' -C metadata=eaa19fd5aec82aae -C extra-filename=-eaa19fd5aec82aae --out-dir /home/ubuntu/projects/my/target/debug/deps -L dependency=/home/ubuntu/projects/my/target/debug/deps --cap-lints allow -Z threads=4` (signal: 6, SIGABRT: process abort signal)
```

<details><summary><strong>Backtrace</strong></summary>
<p>

```
   0:     0x79eee978aafc - std::backtrace_rs::backtrace::libunwind::trace::h5e85954398d12ce3
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x79eee978aafc - std::backtrace_rs::backtrace::trace_unsynchronized::h7416598e16d9343f
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x79eee978aafc - std::sys_common::backtrace::_print_fmt::hc921464b54ab3722
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x79eee978aafc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hac66d34f6a85c7ee
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x79eee97ddc80 - core::fmt::rt::Argument::fmt::hbdd6577954000d6e
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/core/src/fmt/rt.rs:142:9
   5:     0x79eee97ddc80 - core::fmt::write::h6c4f087e5a6c1ba2
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/core/src/fmt/mod.rs:1120:17
   6:     0x79eee977e9af - std::io::Write::write_fmt::hac30ac3c892ea11e
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/std/src/io/mod.rs:1762:15
   7:     0x79eee978a8e4 - std::sys_common::backtrace::_print::h71743d6b3e3b1e41
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x79eee978a8e4 - std::sys_common::backtrace::print::h7f1e7fb2369c92a0
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x79eee978d577 - std::panicking::default_hook::{{closure}}::hf1c8571d28948191
  10:     0x79eee978d2df - std::panicking::default_hook::hd959e15d96d8333b
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/std/src/panicking.rs:292:9
  11:     0x79eeec4f3410 - std[5f6dbc7992e36f36]::panicking::update_hook::<alloc[73e8f31ebd2d06b4]::boxed::Box<rustc_driver_impl[1b37cd9153daf3ad]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x79eee978dcb8 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h583f85f885642a98
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/alloc/src/boxed.rs:2021:9
  13:     0x79eee978dcb8 - std::panicking::rust_panic_with_hook::h51b7b3de85b330a5
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/std/src/panicking.rs:783:13
  14:     0x79eee978d9d9 - std::panicking::begin_panic_handler::{{closure}}::h9f9c9a467f60d8ba
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/std/src/panicking.rs:649:13
  15:     0x79eee978afc6 - std::sys_common::backtrace::__rust_end_short_backtrace::h037a6ad83e4b9233
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x79eee978d772 - rust_begin_unwind
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/std/src/panicking.rs:645:5
  17:     0x79eee97da365 - core::panicking::panic_fmt::h9cec6616f663903f
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/core/src/panicking.rs:72:14
  18:     0x79eeecdc2575 - rustc_query_system[886bde11500d09fb]::query::job::deadlock
  19:     0x79eeec4eb63c - std[5f6dbc7992e36f36]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c52b5cc031b18b22]::util::run_in_thread_pool_with_globals<rustc_interface[c52b5cc031b18b22]::interface::run_compiler<core[b21e5049fb800f2c]::result::Result<(), rustc_span[2f0fd5f8ae050e80]::ErrorGuaranteed>, rustc_driver_impl[1b37cd9153daf3ad]::run_compiler::{closure#0}>::{closure#0}, core[b21e5049fb800f2c]::result::Result<(), rustc_span[2f0fd5f8ae050e80]::ErrorGuaranteed>>::{closure#2}::{closure#1}, ()>
  20:     0x79eeec4f5661 - <<std[5f6dbc7992e36f36]::thread::Builder>::spawn_unchecked_<rustc_interface[c52b5cc031b18b22]::util::run_in_thread_pool_with_globals<rustc_interface[c52b5cc031b18b22]::interface::run_compiler<core[b21e5049fb800f2c]::result::Result<(), rustc_span[2f0fd5f8ae050e80]::ErrorGuaranteed>, rustc_driver_impl[1b37cd9153daf3ad]::run_compiler::{closure#0}>::{closure#0}, core[b21e5049fb800f2c]::result::Result<(), rustc_span[2f0fd5f8ae050e80]::ErrorGuaranteed>>::{closure#2}::{closure#1}, ()>::{closure#1} as core[b21e5049fb800f2c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  21:     0x79eee9797b75 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h60c39ebe8387f1c8
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/alloc/src/boxed.rs:2007:9
  22:     0x79eee9797b75 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1ab2eeceecb887d4
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/alloc/src/boxed.rs:2007:9
  23:     0x79eee9797b75 - std::sys::unix::thread::Thread::new::thread_start::h5193a614b38f3ff0
                               at /rustc/2f8d81f9dbac6b8df982199f69da04a4c8357227/library/std/src/sys/unix/thread.rs:108:17
  24:     0x79eee9494ac3 - <unknown>
  25:     0x79eee9526850 - <unknown>
  26:                0x0 - <unknown>
```

</p>
</details>