Skip to content
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

Scoped thread panic messages unexpectedly interleaving in stderr output #822

Closed
AronParker opened this issue May 4, 2022 · 2 comments
Closed

Comments

@AronParker
Copy link

Consider the following code:

use crossbeam_utils::thread;

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

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

When running it will interleave the panic messages written to stderr:

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

or

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

or

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

This hurts readability. I believe in order to fix this, it would be helpful to preferably suppress the output. Alternatively one could serialize the writes, but given that spawn() provides a Result with the panic, I believe it is best left to the programmer on what to do with the panic.

@AronParker
Copy link
Author

Apparently this is a rust issue: rust-lang/rust#96706 (comment)

@taiki-e
Copy link
Member

taiki-e commented May 4, 2022

This is not a problem specific to scoped threads, so any "fixes" (if exist) on this need to be done upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants