Skip to content

doing some concurrency homework and got a compile-time panic, reporting as requested #139887

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
zsalke opened this issue Apr 16, 2025 · 2 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@zsalke
Copy link

zsalke commented Apr 16, 2025

Code

<code>
use std::thread;
use std::sync::{Mutex, Condvar};

fn main() {

    static SIZE: usize = 5;

    let m_vec = Mutex::new(vec![0,0,0,0,0]);
    let m_count = Mutex::new(0);
    let mut consume = 0;
    let mut produce = 0;
    let cv_empty = Condvar::new();
    let cv_full = Condvar::new();


    thread::scope(|t| {
        t.spawn( || {
            //update the numbers in the vector
            for _ in 0..100 {
                let mut count = m_count.lock().unwrap();

                while *count == 5 {
                    count = cv_full.wait(count).unwrap(); 
                }

                m_vec.lock().unwrap()[produce%5]=produce;
                produce+= 1;
                *count+=1;

                cv_empty.notify_one();
            }
        });
        //print the numbers the vector
        t.spawn( || {
            for _ in 0..100 {
               let mut count = m_count.lock().unwrap();
                
                while *count == 0 {
                    count = cv_empty.wait(count).unwrap();
                }

                println!("{}",m_vec.lock().unwrap()[consume%5]);
                consume+=1;
                *count-=1;

                cv_full.notify_one();
            }
        });
    });

}

Meta

rustc --version --verbose:

<version>
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

<output>
thread 'coordinator' panicked at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/compiler/rustc_codegen_ssa/src/back/write.rs:1846:6:
failed to spawn work thread: Os { code: 11, kind: WouldBlock, message: "Resource temporarily unavailable" }

[stack backtrace redacted for concision] 

error: the compiler unexpectedly panicked. this is a bug.

query stack during panic:
end of query stack
thread 'rustc' panicked at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/compiler/rustc_codegen_ssa/src/back/write.rs:2052:17:
/rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/compiler/rustc_codegen_ssa/src/back/write.rs:2052:17: panic during codegen/LLVM phase
Backtrace

<backtrace>
   0:     0x79eea6301f05 - std::backtrace_rs::backtrace::libunwind::trace::h23054e327d0d4b55
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x79eea6301f05 - std::backtrace_rs::backtrace::trace_unsynchronized::h0cc587407d7f7f64
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x79eea6301f05 - std::sys_common::backtrace::_print_fmt::h4feeb59774730d6b
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x79eea6301f05 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd736fd5964392270
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x79eea6352c4b - core::fmt::rt::Argument::fmt::h105051d8ea1ade1e
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/fmt/rt.rs:165:63
   5:     0x79eea6352c4b - core::fmt::write::hc6043626647b98ea
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/fmt/mod.rs:1168:21
   6:     0x79eea62f6bdf - std::io::Write::write_fmt::h0d24b3e0473045db
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/io/mod.rs:1835:15
   7:     0x79eea6301cde - std::sys_common::backtrace::_print::h62df6fc36dcebfc8
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x79eea6301cde - std::sys_common::backtrace::print::h45eb8174d25a1e76
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x79eea6304719 - std::panicking::default_hook::{{closure}}::haf3f0170eb4f3b53
  10:     0x79eea63044ba - std::panicking::default_hook::hb5d3b27aa9f6dcda
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:298:9
  11:     0x79eea2c150c1 - std[fba9fafec3bdacf8]::panicking::update_hook::<alloc[a325a9cea6fa5e89]::boxed::Box<rustc_driver_impl[ce01f96e2e949677]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x79eea6304e4b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h2026a29033a1b9f6
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/alloc/src/boxed.rs:2077:9
  13:     0x79eea6304e4b - std::panicking::rust_panic_with_hook::h6b49d59f86ee588c
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:799:13
  14:     0x79eea6304bc4 - std::panicking::begin_panic_handler::{{closure}}::hd4c2f7ed79b82b70
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:664:13
  15:     0x79eea63023c9 - std::sys_common::backtrace::__rust_end_short_backtrace::h2946d6d32d7ea1ad
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x79eea63048f7 - rust_begin_unwind
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:652:5
  17:     0x79eea634f1e3 - core::panicking::panic_fmt::ha02418e5cd774672
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/panicking.rs:72:14
  18:     0x79eea634f856 - core::result::unwrap_failed::h55f86ada3ace5ed2
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/result.rs:1679:5
  19:     0x79eea4c3d12f - rustc_codegen_ssa[735fc0e7ecd285d]::back::write::spawn_work::<rustc_codegen_llvm[7d5a1ffcd7eaee82]::LlvmCodegenBackend>
  20:     0x79eea4c3ee0d - rustc_codegen_ssa[735fc0e7ecd285d]::back::write::start_executing_work::<rustc_codegen_llvm[7d5a1ffcd7eaee82]::LlvmCodegenBackend>::{closure#5}
  21:     0x79eea4c3de42 - std[fba9fafec3bdacf8]::sys_common::backtrace::__rust_begin_short_backtrace::<<rustc_codegen_llvm[7d5a1ffcd7eaee82]::LlvmCodegenBackend as rustc_codegen_ssa[735fc0e7ecd285d]::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa[735fc0e7ecd285d]::back::write::start_executing_work<rustc_codegen_llvm[7d5a1ffcd7eaee82]::LlvmCodegenBackend>::{closure#5}, core[1a380081440346cb]::result::Result<rustc_codegen_ssa[735fc0e7ecd285d]::back::write::CompiledModules, ()>>::{closure#0}, core[1a380081440346cb]::result::Result<rustc_codegen_ssa[735fc0e7ecd285d]::back::write::CompiledModules, ()>>
  22:     0x79eea4c3dc81 - <<std[fba9fafec3bdacf8]::thread::Builder>::spawn_unchecked_<<rustc_codegen_llvm[7d5a1ffcd7eaee82]::LlvmCodegenBackend as rustc_codegen_ssa[735fc0e7ecd285d]::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa[735fc0e7ecd285d]::back::write::start_executing_work<rustc_codegen_llvm[7d5a1ffcd7eaee82]::LlvmCodegenBackend>::{closure#5}, core[1a380081440346cb]::result::Result<rustc_codegen_ssa[735fc0e7ecd285d]::back::write::CompiledModules, ()>>::{closure#0}, core[1a380081440346cb]::result::Result<rustc_codegen_ssa[735fc0e7ecd285d]::back::write::CompiledModules, ()>>::{closure#2} as core[1a380081440346cb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  23:     0x79eea630ee3b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hdf5fcef8be77a431
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/alloc/src/boxed.rs:2063:9
  24:     0x79eea630ee3b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8e8c5ceee46ee198
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/alloc/src/boxed.rs:2063:9
  25:     0x79eea630ee3b - std::sys::pal::unix::thread::Thread::new::thread_start::hb85dbfa54ba503d6
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys/pal/unix/thread.rs:108:17
  26:     0x79ee9f89caa4 - start_thread
                               at ./nptl/pthread_create.c:447:8
  27:     0x79ee9f929c3c - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
  28:                0x0 - <unknown>

<beginning of second panic backtrace>

  0:     0x79eea6301f05 - std::backtrace_rs::backtrace::libunwind::trace::h23054e327d0d4b55
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x79eea6301f05 - std::backtrace_rs::backtrace::trace_unsynchronized::h0cc587407d7f7f64
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x79eea6301f05 - std::sys_common::backtrace::_print_fmt::h4feeb59774730d6b
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x79eea6301f05 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd736fd5964392270
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x79eea6352c4b - core::fmt::rt::Argument::fmt::h105051d8ea1ade1e
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/fmt/rt.rs:165:63
   5:     0x79eea6352c4b - core::fmt::write::hc6043626647b98ea
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/fmt/mod.rs:1168:21
   6:     0x79eea62f6bdf - std::io::Write::write_fmt::h0d24b3e0473045db
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/io/mod.rs:1835:15
   7:     0x79eea6301cde - std::sys_common::backtrace::_print::h62df6fc36dcebfc8
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x79eea6301cde - std::sys_common::backtrace::print::h45eb8174d25a1e76
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x79eea6304719 - std::panicking::default_hook::{{closure}}::haf3f0170eb4f3b53
  10:     0x79eea63044ba - std::panicking::default_hook::hb5d3b27aa9f6dcda
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:298:9
  11:     0x79eea2c150c1 - std[fba9fafec3bdacf8]::panicking::update_hook::<alloc[a325a9cea6fa5e89]::boxed::Box<rustc_driver_impl[ce01f96e2e949677]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x79eea6304e4b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h2026a29033a1b9f6
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/alloc/src/boxed.rs:2077:9
  13:     0x79eea6304e4b - std::panicking::rust_panic_with_hook::h6b49d59f86ee588c
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:799:13
  14:     0x79eea30957d5 - std[fba9fafec3bdacf8]::panicking::begin_panic::<alloc[a325a9cea6fa5e89]::string::String>::{closure#0}
  15:     0x79eea3091276 - std[fba9fafec3bdacf8]::sys_common::backtrace::__rust_end_short_backtrace::<std[fba9fafec3bdacf8]::panicking::begin_panic<alloc[a325a9cea6fa5e89]::string::String>::{closure#0}, !>
  16:     0x79eea308d9f1 - std[fba9fafec3bdacf8]::panicking::begin_panic::<alloc[a325a9cea6fa5e89]::string::String>
  17:     0x79eea310e6ed - rustc_middle[ecc07153edf3c281]::util::bug::opt_span_bug_fmt::<rustc_span[4d50fd03223eefaa]::span_encoding::Span>::{closure#0}
  18:     0x79eea30f77ea - rustc_middle[ecc07153edf3c281]::ty::context::tls::with_opt::<rustc_middle[ecc07153edf3c281]::util::bug::opt_span_bug_fmt<rustc_span[4d50fd03223eefaa]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  19:     0x79eea30f766b - rustc_middle[ecc07153edf3c281]::ty::context::tls::with_context_opt::<rustc_middle[ecc07153edf3c281]::ty::context::tls::with_opt<rustc_middle[ecc07153edf3c281]::util::bug::opt_span_bug_fmt<rustc_span[4d50fd03223eefaa]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  20:     0x79eea0cee7d0 - rustc_middle[ecc07153edf3c281]::util::bug::bug_fmt
  21:     0x79eea4e08d30 - <rustc_codegen_llvm[7d5a1ffcd7eaee82]::LlvmCodegenBackend as rustc_codegen_ssa[735fc0e7ecd285d]::traits::backend::CodegenBackend>::join_codegen
  22:     0x79eea4a8d18b - <rustc_interface[c31201428b712578]::queries::Linker>::link
  23:     0x79eea4c12862 - rustc_interface[c31201428b712578]::interface::run_compiler::<core[1a380081440346cb]::result::Result<(), rustc_span[4d50fd03223eefaa]::ErrorGuaranteed>, rustc_driver_impl[ce01f96e2e949677]::run_compiler::{closure#0}>::{closure#1}
  24:     0x79eea4d47869 - std[fba9fafec3bdacf8]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c31201428b712578]::util::run_in_thread_with_globals<rustc_interface[c31201428b712578]::interface::run_compiler<core[1a380081440346cb]::result::Result<(), rustc_span[4d50fd03223eefaa]::ErrorGuaranteed>, rustc_driver_impl[ce01f96e2e949677]::run_compiler::{closure#0}>::{closure#1}, core[1a380081440346cb]::result::Result<(), rustc_span[4d50fd03223eefaa]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1a380081440346cb]::result::Result<(), rustc_span[4d50fd03223eefaa]::ErrorGuaranteed>>
  25:     0x79eea4d4766a - <<std[fba9fafec3bdacf8]::thread::Builder>::spawn_unchecked_<rustc_interface[c31201428b712578]::util::run_in_thread_with_globals<rustc_interface[c31201428b712578]::interface::run_compiler<core[1a380081440346cb]::result::Result<(), rustc_span[4d50fd03223eefaa]::ErrorGuaranteed>, rustc_driver_impl[ce01f96e2e949677]::run_compiler::{closure#0}>::{closure#1}, core[1a380081440346cb]::result::Result<(), rustc_span[4d50fd03223eefaa]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1a380081440346cb]::result::Result<(), rustc_span[4d50fd03223eefaa]::ErrorGuaranteed>>::{closure#2} as core[1a380081440346cb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  26:     0x79eea630ee3b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hdf5fcef8be77a431
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/alloc/src/boxed.rs:2063:9
  27:     0x79eea630ee3b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8e8c5ceee46ee198
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/alloc/src/boxed.rs:2063:9
  28:     0x79eea630ee3b - std::sys::pal::unix::thread::Thread::new::thread_start::hb85dbfa54ba503d6
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys/pal/unix/thread.rs:108:17
  29:     0x79ee9f89caa4 - start_thread
                               at ./nptl/pthread_create.c:447:8
  30:     0x79ee9f929c3c - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
  31:                0x0 - <unknown>

@zsalke zsalke added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 16, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 16, 2025
@bjorn3
Copy link
Member

bjorn3 commented Apr 16, 2025

The OS returned a resource exhaustion error when rustc tried to spawn a thread. I guess we could change it to show a nicer error, but rustc is likely not at fault here.

@ChrisDenton
Copy link
Member

We definitely shouldn't ICE in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants