The question is related to alleged disadvantage of std::thread
. Yesterday I was casually traversing the popular open source distributed proxy envoy by Lyft. When I was studying their threading portion i came across a comment which caught my eye. The comment says the following:
Wrapper for a pthread thread. We don't use std::thread because it eats exceptions and leads to unusable stack traces
I am not sure what does it mean by eats exception and unusable stack traces.
Can anybody explain what it means and why std::thread
results in a non reliable stack trace?
Presumably they have some custom exception handling mechanism which logs uncaught exceptions with a stack trace.
std::thread
is defined to catch unhandled exceptions and call std::terminate:
if it terminates by throwing an exception, std::terminate is called
https://en.cppreference.com/w/cpp/thread/thread
The C++ Standard says the following regarding uncaught exceptions in std::threads:
In [thread.thread.constr]:
... If the invocation of INVOKE(DECAY_COPY(std::forward(f)), DECAY_COPY(std::forward(args))...) terminates with an uncaught exception, terminate shall be called.
According to this, the answer to
Can anybody explain what it means and why
std::thread
results in a non reliable stack trace?
is that unless handled in a dedicated fashion inside the thread proc itself, the thread will just terminate upon an exception, and the code stack that started the thread will not be any the wiser regarding what had transpired.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With