terminate called without an active exception [1] 18090 abort ./bin/concurrency
If neither join or detach is called with a std::thread object that has associated executing thread then during that object’s destruct-or it will terminate the program. Because inside the destruct-or it checks if Thread is Still Join-able then Terminate the program i.e.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<iostream> #include<thread> #include<algorithm> classWorkerThread { public: voidoperator()() { std::cout<<"Worker Thread "<<std::endl; } }; intmain() { std::thread threadObj( (WorkerThread()) ); // Program will terminate as we have't called either join or detach with the std::thread object. // Hence std::thread's object destructor will terminate the program return0; }