Deadlock while using boost::asio::deadline_timer in Windows dll

后端 未结 1 1062
别那么骄傲
别那么骄傲 2021-01-20 10:13

I am trying to use Boost-Deadlinetimer inside a DLL, which is loaded using boost::dll::shared_library. Following code-snippets are reduced to the essentials.

Example

相关标签:
1条回答
  • 2021-01-20 10:45

    Windows has a LoaderLock which is held from the call to LoadLibrary until it returns.

    This lock is used by the Windows system to ensure that the process remains stable, as cascaded DLLs are properly reference counted.

    Globals which are created within a DLL, are constructed by dynamic initialization just before DllMain runs (DLL_PROCESS_ATTACH), and destroyed just after DllMain finishes (DLL_PROCESS_DETACH).

    When you create a DLL with a global variable, you need to follow the rules in the link, and avoid...

    • Loading DLLs
    • Using Locks - cause of lock-inversion
    • Creating processes
    • Reading the registry
    • Creating/destroying threads
    • using the StringType functions.

    The easiest way to cope with this would be having a separate initialize function which is called after LoadLibrary, and a Uninitialize function called before the final FreeLibrary where global variables are separately initialized.

    0 讨论(0)
提交回复
热议问题