简体   繁体   English

Windows上的std :: mutex :: lock失败,错误代码3

[英]std::mutex::lock fails on Windows, error code 3

I use std::mutex and std::lock_guard in a proper RAII manner throughout my application: 我在整个应用程序中以正确的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;
};

It always worked, but I've added parallelism to one more class just now, and in this new class locker throws std::system_error . 它总是有效,但我刚刚在另一个类中添加了并行性,并且在这个新的类locker抛出了std::system_error The problem is here ( xthread header): 问题出在这里( xthread头):

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

_Mtx_lock returns 3 while the expected value is 0. No idea what 3 means. _Mtx_lock返回3而预期值为0.不知道3意味着什么。

VS2013, v120_x64 runtime. VS2013,v120_x64运行时。

The error as mentioned by @Phantom (_Thrd_busy) implies that the lock had been recursively taken. @Phantom(_Thrd_busy)提到的错误意味着已经递归地获取了锁。 Also see this answer 另见这个答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM