【发布时间】:2015-08-24 19:21:29
【问题描述】:
我在整个申请过程中以适当的 RAII 方式使用 std::mutex 和 std::lock_guard:
struct Foo {
int f() const
{
std::lock_guard<std::mutex> locker(m_mutex);
return m_i;
}
private:
int m_i = 0;
mutable std::mutex m_mutex;
};
它总是有效,但我刚刚在另一个类中添加了并行性,并且在这个新类中 locker 抛出 std::system_error。问题出在这里(xthread 标头):
inline int _Mtx_lockX(_Mtx_t *_Mtx)
{ // throw exception on failure
return (_Check_C_return(_Mtx_lock(_Mtx)));
}
_Mtx_lock 在预期值为 0 时返回 3。不知道 3 是什么意思。
VS2013,v120_x64 运行时。
【问题讨论】:
-
贴出实例化互斥锁的代码。
-
使您的互斥锁可变...您正在从 const 函数修改它的状态。它不应该编译,imo
-
编译失败here
-
@VioletGiraffe,已接受,但提供无法编译的代码会使我们远离真正的问题。
-
错误代码 3 似乎是 xthreads.h 顶部
_Thrd_busy的值。
标签: c++ windows multithreading c++11 mutex