Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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. The problem is here (xthread header):

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.

VS2013, v120_x64 runtime.

like image 711
Violet Giraffe Avatar asked Jun 09 '15 19:06

Violet Giraffe


1 Answers

The error as mentioned by @Phantom (_Thrd_busy) implies that the lock had been recursively taken. Also see this answer

like image 71
Werner Erasmus Avatar answered Nov 19 '22 05:11

Werner Erasmus