Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can two threads simultaneously panic without aborting?

Tags:

rust

I know that if a thread panics while it is panicking, that it will abort the program. However, today I saw someone make the claim that two independent threads simultaneously panicking will abort the process as well. Is it actually true that two independent threads panicking simultaneously will abort the process, the same as a single thread panicking twice?

like image 642
cyborg Avatar asked May 29 '26 05:05

cyborg


1 Answers

This will not abort the process. The panicking/unwinding status of each thread is independent. Two threads both panicking at the same time will:

  • both write their panic messages to stderr (or otherwise do what the global panic hook does), and
  • both return errors from their JoinHandles,

and an application could, of course, choose to abort if it sees multiple such panics, but there is nothing in the Rust standard library or compiler that will cause an abort in this case.

like image 165
Kevin Reid Avatar answered May 31 '26 18:05

Kevin Reid