0

I've just encountered a weird and devastating problem that I couldn't find any information about it anywhere.

asio::steady_timer timer(m_context);

This asio::steady_timer works perfectly fine if I'm building it as an EXE, but if it's built as a DLL it will be stuck waiting for WaitForSingleObject (in win_thread.ipp file, line 106) whenever initialize a asio::steady_timer, please take a look at the picture below.

asio::steady_timer stuck

This DLL is just an empty project, it only includes the asio.hpp file. I've found this_article about a problem that might be relevant, but still found no way to debug or fix this.

Am I doing something wrong, or is this the library's bug?

Thanks for your time!

thedemons
  • 1,139
  • 2
  • 9
  • 25
  • Thanks for the answer, I post the screenshot for the stack traces, the code is really just that 1 line – thedemons Jun 15 '22 at 11:37
  • @thedemons The code is **crucially** inside DllMain, it is *not* the single line. – sehe Jun 15 '22 at 11:48
  • 1
    You need to redesign your code to make required initialization by caller request. `DllMain` is not a place for non-trivial tasks. – Alex F Jun 15 '22 at 11:52

1 Answers1

0

This was solved by making these two class members or global variables and not initializing them in the entry point of the DLL.

asio::io_context context;
asio::steady_timer timer(context);
thedemons
  • 1,139
  • 2
  • 9
  • 25