replacing boost:: mutex
replacing boost:: mutex
我有一个程序,代码是:
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。我能够编译并运行!
希望这能有所帮助。
相关文章:
- BOOST :: MUTEX版本与调试构建
- Use boost strand and std::mutex
- 将 boost::thread 与 C++11 std::mutex 混合使用是否安全?
- 使用Boost ::与包含Boost :: Mutex的类绑定
- boost::interprocess_mutex与进程本地boost::mutex
- 如何try_lock boost::unique_lock<boost::mutex>
- Boost Mutex implementation for Windows
- 为什么我必须有一个 boost::mutex for boost::condition_variable
- boost::mutex和boost::timed_mutex的性能差异
- 如何使用boost::mutex作为std::map中的映射类型
- Boost::类中的Mutex不是线程安全的
- boost::mutex::timed_lock not on Linux
- 与 boost::interprocess_mutex 相比,为什么不在共享内存中使用 boost::mutex
- boost::mutex 无法帮助避免C++程序中的竞争条件
- 尝试等待 boost::condition_Variable 时出现"unique_lock has no mutex: Operation not permitted"错误
- 为什么 boost::mutex 比 std::mutex 快 vs2013.
- boost::mutex 在 Visual Studio 中支持 try_lock_for,但在 Xcode 中不支持
- 与 std::d eque 一起使用时,不能将 Boost::mutex 作为私有类成员吗?
- boost::mutex 和 boost::timed_mutex 之间的区别
- 什么会导致异常 16:抛出"mutex: Resource busy"(使用 Boost / BB10)?