std::thread执行异常解决:terminate called without an active exception

使用std::thread+lamba时,处理不当容易在成段错误或抛出异常: 段错误:一般lamba表达式使用了传引用[&]方式,导致使用了释放的局部变量,应该使用传值[=]方式;
抛出异常: 线程创建后,如果不关心线程执行情况,可调用detach使线程分离:
void GpioBeep::beepOutButton(int delayMs)
{
std::thread tdTmp([=, delayMs](){
gpioWrite(m_pin, BEEP_ON);
std::this_thread::sleep_for(std::chrono::milliseconds(delayMs));
gpioWrite(m_pin, BEEP_OFF);
std::this_thread::sleep_for(std::chrono::mill

std::thread执行异常解决:terminate called without an active exception最先出现在Python成神之路

版权声明:
作者:主机优惠
链接:https://www.techfm.club/p/8620.html
来源:TechFM
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>