2013-02-26 49 views
0

我有一个程序使用此代码:更换的boost ::互斥

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 :: mutex代码,并找到一种方法来克服这个编译器错误。我在VS2010上使用VS2012和C++上的C#开始使用。 CLI也在VS2010上。

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

+0

STL没有并发编程库。 C++标准库在C++ 11之前都没有。 – juanchopanza 2013-02-26 12:29:59

+1

您使用的是最新版本的Boost? – 2013-02-26 12:38:22

+0

你正在使用哪种版本的boost? – 2013-02-26 12:39:54

回答

4

偏离主题,但请注意,您并未正确地等待条件变量:您应该将状态(此例中为布尔值)与它关联并等待循环。否则,您的代码可能会错过状态通知并永久挂起,或者收到虚假唤醒并过早完成等待。请参阅http://www.boost.org/doc/libs/1_53_0/doc/html/thread/synchronization.html#thread.synchronization.condvar_ref

+1

而且你应该使用一个共同的互斥体进行同步... – 2013-02-26 13:41:30

+0

谢谢我会解决它。 – Gilad 2013-02-26 14:04:07