If I create a simple program like...
#include <mutex>
std::mutex gMutex;
int main()
{
gMutex.lock();
gMutex.unlock();
return 0;
}
... the code executes without issue.
However, in another app, when I create a global instance of std::mutex
and attempt to call the lock()
method, an exception is raised. (I don't have the exact exception text, but it was complaining about an internal of the mutex object being null)
Looking at the internal state of the mutex object that fails, I see that the _Mtx_storage
member has it's _Val
set to 0.000000000000000000
and it's _Pad
member is set to a non-null value which points to a small buffer (I think it was 0x4f bytes in size) of null bytes.
When I compare this state to that in the simple program above, I see that the _Mtx_storage
state is NOT null (I think it was 0.000000000002
) in the code that works. What would cause it to be null in my other app?
I'm using Visual C++ 2015.
Any ideas are appreciated. Thanks!
Likely the mutex isn't initialized yet. If this code is running before main
, see if you can replicate the problem without the code running before main
.