terminate called without an active exception

解决运行时错误:terminate called without an active exception

运行以下程序:

#include <thread>
#include <iostream>

void my_thread_func()
{
    std::cout<<"hello"<<std::endl;
}

int main()
{
    std::thread t(my_thread_func);
}

提示错误为:

terminate called without an active exception hello 已放弃

考虑应该是主线程结束了子线程还没有结束导致的。

应该在main函数中增加:

t.join();


blog comments powered by Disqus

Published

22 March 2012

Category

c_cpp