C++11 std::mutex in Visual Studio 2012 deadlock when locked from DllMain()

前端 未结 2 666
攒了一身酷
攒了一身酷 2020-12-01 20:04

I am seeing a deadlock with std::mutex when the mutex is locked from DllMain() Below is a minimal DLL test case that exhibits the problem for me. M

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 20:47

    It seems that using QueueUserAPC() to queue initialization is always executed before main() but out of the dreaded loader lock. This looks like a solution to my problem.

    EDIT 1

    After some testing it seems that the APC method works if I queue the APC from DllMain() but it does not work if I queue the APC from a ctor of a static global instance of a class. IOW, using the APC is not uniformly usable across all possible combinations of compilers and build modes for me.

提交回复
热议问题