std: multithreaded crash during thread init #41

Open
opened 2025-03-02 17:17:45 +02:00 by alnyan · 1 comment
Owner

Program: tst

Source:

use std::{thread, time::Duration};

fn main() {
    let mut threads = vec![];
    for i in 0..4 {
        let jh = thread::Builder::new()
            .name(format!("tst-thread-{i}"))
            .spawn(move || {
                let current = thread::current();
                for _ in 0..100 {
                    println!("Hi from thread {:?}", current.name());
                    thread::sleep(Duration::from_secs(1));
                }
            })
            .unwrap();

        threads.push(jh);
    }

    for thread in threads.into_iter() {
        thread.join().unwrap();
    }
}

Log:

000016:0:libk::task::binary::elf:192: Loading ELF virtual 0x0..0x1d000 -> real 0x19fce000..0x19feb000
000016:0:libk::task::binary:185: stack: 0x3000000..0x3020000
Hi from thread Some("tst-thread-0")
000016:2:ptrace:tst (21) thread '
Hi from thread Some("tst-thread-1")
thread '000016Hi from thread Some("tst-thread-3")
:2:ptrace:tst (21) tst-thread-2
tst-thread-2000016:2:ptrace:tst (21) ' panicked at
' panicked at 000016:2:ptrace:tst (21) std/src/sync/once.rs
std/src/sync/once.rs000016:2:ptrace:tst (21) :
:000016:2:ptrace:tst (21) 217
217000016:2:ptrace:tst (21) :
:000016:2:ptrace:tst (21) 20
20000016:2:ptrace:tst (21) :

:
000016:2:ptrace:tst (21) one-time initialization may not be performed recursively
one-time initialization may not be performed recursively000016:2:ptrace:tst (21)


000016:2:ptrace:tst (21) note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
000016:2:libk::task::thread:373: #26: raise signal Aborted
000016:2:yggdrasil_kernel::arch::x86_64::exception:127: InvalidOpcode in #26 ("tst-thread-2")
000016:2:yggdrasil_kernel::arch::x86_64::exception:128: ip = 23:19fe0164
000016:2:yggdrasil_kernel::arch::x86_64::exception:129: cr3 = 0x055b1000
000016:2:ptrace:tst (21) runtime: terminated by signal: Aborted
Program: `tst` Source: ```rust use std::{thread, time::Duration}; fn main() { let mut threads = vec![]; for i in 0..4 { let jh = thread::Builder::new() .name(format!("tst-thread-{i}")) .spawn(move || { let current = thread::current(); for _ in 0..100 { println!("Hi from thread {:?}", current.name()); thread::sleep(Duration::from_secs(1)); } }) .unwrap(); threads.push(jh); } for thread in threads.into_iter() { thread.join().unwrap(); } } ``` Log: ``` 000016:0:libk::task::binary::elf:192: Loading ELF virtual 0x0..0x1d000 -> real 0x19fce000..0x19feb000 000016:0:libk::task::binary:185: stack: 0x3000000..0x3020000 Hi from thread Some("tst-thread-0") 000016:2:ptrace:tst (21) thread ' Hi from thread Some("tst-thread-1") thread '000016Hi from thread Some("tst-thread-3") :2:ptrace:tst (21) tst-thread-2 tst-thread-2000016:2:ptrace:tst (21) ' panicked at ' panicked at 000016:2:ptrace:tst (21) std/src/sync/once.rs std/src/sync/once.rs000016:2:ptrace:tst (21) : :000016:2:ptrace:tst (21) 217 217000016:2:ptrace:tst (21) : :000016:2:ptrace:tst (21) 20 20000016:2:ptrace:tst (21) : : 000016:2:ptrace:tst (21) one-time initialization may not be performed recursively one-time initialization may not be performed recursively000016:2:ptrace:tst (21) 000016:2:ptrace:tst (21) note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace 000016:2:libk::task::thread:373: #26: raise signal Aborted 000016:2:yggdrasil_kernel::arch::x86_64::exception:127: InvalidOpcode in #26 ("tst-thread-2") 000016:2:yggdrasil_kernel::arch::x86_64::exception:128: ip = 23:19fe0164 000016:2:yggdrasil_kernel::arch::x86_64::exception:129: cr3 = 0x055b1000 000016:2:ptrace:tst (21) runtime: terminated by signal: Aborted ```
alnyan added the
bug
crash
scope
userspace-std
labels 2025-03-02 17:17:46 +02:00
Author
Owner

Binary that crashes

Binary that crashes
59 KiB
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: alnyan/yggdrasil#41
No description provided.