std::thread cause deadlock in DLLMain

前端 未结 4 959
无人共我
无人共我 2020-12-28 11:14

So, this is what I\'m talking about: std is complex.

In VS2013 this simple program will cause a deadlock.

#include 
#include 

        
4条回答
  •  生来不讨喜
    2020-12-28 11:37

    std::thread creates a C++ thread. It means you can rely on the C++ library in that thread. This means certain shared data structures must be set up, which force synchronization (you might create multiple threads in parallel). The stack trace clearly shows this: std::_Cnd_waitX is clearly a part of the Standard Library, and is clearly synchronizing. Synchronizing is blacklisted in the document you mentioned, so this crash isn't a big surprise.

    Further up the stack we see Concurrency::. This is specific to Visual Studio versions up to VS2015. This means you may luck out in VS2015. Doing thread synchronization in DllMain is not a guaranteed crash. Just quite possible.

提交回复
热议问题