replacing boost:: mutex

replacing boost:: mutex

本文关键字:mutex boost replacing      更新时间:2023-10-16

我有一个程序,代码是:

mutable boost::condition_variable cvRun;
void CAteEngineInternal::RunSync()
{
    boost::mutex m;
    boost::unique_lock<boost::mutex> lock(m);
    Run();
    //wait for run to complete
    cvRun.wait(lock);
}
int  CAteEngineInternal::RunXSync(int FramesToRun)
{
    boost::mutex m;
    boost::unique_lock<boost::mutex> lock(m);
    int retVal = RunX(FramesToRun);
    //wait for run to complete
    cvRun.wait(lock);
    return retVal;
}

void CAteEngineInternal::OnRunCompleted(int /* status */)
{
    cvRun.notify_all();
}

我正在使用CLI,并收到以下错误:
basic_timed_mutex.hpp(216(:致命错误C1001:编译器中发生内部错误

我想替换这个boost::互斥代码,并找到一种方法来克服这个编译器错误。我在VS2012上使用C#,在VS2010上使用C++。CLI也在VS2010上。

有什么建议吗?我需要它是跨平台的,并且能够在VS2010中编译它。

脱离主题,但请注意,您没有正确地等待条件变量:您应该将state(在本例中为布尔值(与之关联,并在循环中等待。否则,您的代码可能会错过条件通知并永远挂起,或者收到虚假的唤醒并提前完成等待。看见http://www.boost.org/doc/libs/1_53_0/doc/html/thread/synchronization.html#thread.synchronization.condvar_ref

我过去在混合VS2012和VS2010时遇到过这个问题,你真的不应该这样工作。这是个窃听器。

经过两天的搜索,我找到了这个解决方案http://connect.microsoft.com/VisualStudio/feedback/details/753623/fatal-error-c1001

请确保您了解如何正确使用pragma。我能够编译并运行!

希望这能有所帮助。