You can
build it, but when you run it,
Execute
and die when an error occurs.
Error
Message:
Terminate
called out an active extension
Aborted
Problem
Occurs
when coding using "std::thread"
Cause /
Solution
When
coding using "std::thread", it is caused by not inserting
"join"
Example
Code:
class
TEST {
TEST();
~TEST();
void init();
void end();
std::shared_ptr<std::thread> th = nullptr;
void exec(){}
}
void
TEST::init() {
th =
std::make_shared<std::thread>(&TEST::exec , this);
}
void
TEST::end() {
if(th != nullptr) {
th->join();
th = nullptr;
}
}
int
main() {
Test *t = new TEST();
t->init();
if( t != nullptr ) {
delete t;
t = nullptr;
}
// If this
program ends here, an
error will occur.
//add code
t->end();
if( t != nullptr ) {
delete t;
t = nullptr;
}
//solved code !
}
#linux #embedded #C #C++ #debug #error #thread #join
No comments:
Post a Comment