[英]Why does std::mutex throw an exception when I call lock()?
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. 但是,在另一个应用程序中,当我创建
std::mutex
的全局实例并尝试调用lock()
方法时,会引发异常。 (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. 查看失败的互斥对象的内部状态,我看到
_Mtx_storage
成员将_Val
设置为0.000000000000000000
,并将_Pad
成员设置为非空值,该值指向一个小的缓冲区(我认为它是0x4f字节,大小)的空字节。
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. 当我将此状态与上面的简单程序中的状态进行比较时,我看到有效的
_Mtx_storage
状态不为null(我认为是0.000000000002
)。 What would cause it to be null in my other app? 是什么导致它在我的其他应用中为空?
I'm using Visual C++ 2015. 我正在使用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
. 如果此代码在
main
之前运行,请查看是否可以在不将代码在main
之前运行的情况下复制问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.