首页 > 解决方案 > 从 boost::thread 访问对象

问题描述

在我的程序中,我使用以下方法启动循环函数boost::thread

代码是这样的:

void MyClass::StartSim()
{
    _thread = boost::thread(boost::bind(&MyClass::BoostTick, boost::ref(*this)));
}

void MyClass::BoostTick()
{
    while (!_shutdown)
    {
        // do something
    }
}

并且工作正常......现在我有一个这样的功能:

Ray MyClass:GetRay()
{
    // here I use an object that is used inside the while loop
}

但我有例外...

有没有办法避免异常?

提前致谢

标签: c++multithreadingboost

解决方案


推荐阅读