Skip to content

Scoped thread panic messages unexpectedly interleaving in stderr output #96706

Closed
@AronParker

Description

@AronParker

I tried this code:

#![feature(scoped_threads)]

use std::{panic, thread};

fn main() {
    thread::scope(|s| {
        s.spawn(|| {
            panic!("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
        });

        s.spawn(|| {
            panic!("BBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
        });
    });
}

I expected to see the following output:

thread '<unnamed>' panicked at 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', src\main.rs:8:13
thread '<unnamed>' panicked at 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBB', src\main.rs:12:13

As it runs concurrently, of course the order could be reversed.

Instead, the panic messages were interleaved. Here are some examples:

thread 'thread '<unnamed>' panicked at 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBB<unnamed>', ' panicked at 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', src\main.rs:13:13src\main.rs:8:13

thread '<unnamed>' panicked at 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', src\main.rs:thread '<unnamed>' panicked at '8:13BBBBBBBBBBBBBBBBBBBBBBBBBBBBB

thread '<unnamed>' panicked at 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', thread '<unnamed>src\main.rs:8' panicked at 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBB:13

thread '<unnamed>' panicked at 'thread '<unnamed>' panicked at 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBB', AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', src\main.rs:8:13

thread 'thread '<unnamed><unnamed>' panicked at '' panicked at 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBB', ', src\main.rssrc\main.rs::812::1313

As scoped threads panic directly to stderr, I see no measure to prevent this and provide more readable output.

Meta

rustc --version --verbose:

rustc 1.62.0-nightly (7c4b47696 2022-04-30)
binary: rustc
commit-hash: 7c4b47696907d64eff5621a64eb3c6e795a9ec77
commit-date: 2022-04-30
host: x86_64-pc-windows-msvc
release: 1.62.0-nightly
LLVM version: 14.0.1
Backtrace

thread '<unnamed>' panicked at 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', src\main.rs:8:13
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/7c4b47696907d64eff5621a64eb3c6e795a9ec77/library\std\src\panicking.rs:584
   1: core::panicking::panic_fmt
             at /rustc/7c4b47696907d64eff5621a64eb3c6e795a9ec77/library\core\src\panicking.rs:142
   2: hello_world::main::closure$0::closure$0
             at .\src\main.rs:8
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
thread 'main' panicked at 'a scoped thread panicked', src\main.rs:6:5
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/7c4b47696907d64eff5621a64eb3c6e795a9ec77/library\std\src\panicking.rs:584
   1: core::panicking::panic_fmt
             at /rustc/7c4b47696907d64eff5621a64eb3c6e795a9ec77/library\core\src\panicking.rs:142
   2: std::thread::scoped::scope<hello_world::main::closure_env$0,tuple$<> >
             at /rustc/7c4b47696907d64eff5621a64eb3c6e795a9ec77\library\std\src\thread\scoped.rs:155
   3: hello_world::main
             at .\src\main.rs:6
   4: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/7c4b47696907d64eff5621a64eb3c6e795a9ec77\library\core\src\ops\function.rs:248
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\hello_world.exe` (exit code: 101)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`A-panicArea: Panicking machineryA-threadArea: `std::thread`C-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions