c++ - std::mutex::lock 在 Windows 上失败,错误代码 3

标签 c++ windows multithreading c++11 mutex

我在整个应用程序中以适当的 RAII 方式使用 std::mutexstd::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 throws std::system_error。问题出在这里(xthread header):

inline int _Mtx_lockX(_Mtx_t *_Mtx)
{   // throw exception on failure
    return (_Check_C_return(_Mtx_lock(_Mtx)));
}

_Mtx_lock 返回 3,而预期值为 0。不知道 3 是什么意思。

VS2013,v120_x64 运行时。

最佳答案

@Phantom (_Thrd_busy) 提到的错误暗示锁已被递归获取。另见 answer

关于c++ - std::mutex::lock 在 Windows 上失败,错误代码 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30741114/

相关文章:

C++ setTimeout函数?

c++ - 在 C++ 中,指针类型数组的元素是否保证默认初始化为 nullptr?

javascript - Windows 中 Firefox 的行结束行为不一致

python - “self”未定义 - 使用计时器进行线程处理

java - 使用 Java 并发运行多线程任务,直到有足够的输出

c# - 确定 NamedDataSlot 是否存在的最佳方法是什么

c++ - 为 Intranet 主机创建 C++ 命名管道

c++ - 插入排序C实现

C# - Windows ACL - 应用继承权限

windows - 终端上的 git status 暂停列表