DEV Community


Pitfall with C++ Threads

lucpattyn profile image Mukit, Ataul ・1 min read

In one of my programs, I declared a thread object accidentally inside an if condition. I completely forgot - the thread would be destroyed before properly finishing execution when the thread variable goes out of scope. It was heck of a trouble to find the core dump issue :
"terminate called without an active exception
Aborted (core dumped)"

My problematic code:

    std::thread t([&app]() {


Temporary Fix (I got more problems to take care off than to solve this one elegantly):

std::thread t([&app, &runnable]() {

In any case, need to be very careful how and where your thread objects are declared and executed.

Signing off,



Discussion (0)

Forem Open with the Forem app