Thread creation, the CRT and DLL's how is it meant to be done?

后端 未结 2 532
终归单人心
终归单人心 2021-02-10 14:54

So I understand that CreateThread and the CRT can result in memory leaks, signal doesn\'t work, and one should use the _beginthread or _beginthreadex functions.

That is

相关标签:
2条回答
  • 2021-02-10 15:13

    CreateThread and the CRT can result in memory leaks

    No, that's a misunderstanding that's incredibly difficult to get rid of for some reason. Using _beginthread() was necessary back in the previous century, VS6 was the last version of VS that had a CRT that still required it.

    That's been fixed, in no small part to deal with the support for the thread pool added to Windows 2000. Clearly you can't do anything in the CRT to deal with them, those threads are started by the OS itself. The implementation is pretty straight-forward. Wherever the CRT needs a thread-local variable, like the one needed by strtok(), it first checks if TLS storage was already allocated for the thread. If not, it allocates it on-the-fly.

    Just use CreateThread() without fear, implicit of course with the assumption that you no longer use a 14 year old compiler.

    0 讨论(0)
  • 2021-02-10 15:18

    There are two options:

    1. Do not use CRT from the DLL.
    2. Ship multiple DLLs, one for every supported tool-chain version.

    Where 1 is not an acceptable solution, 2 is chosen. Note that you have to ship multiple DLLs anyway, e.g. if your users compile for 32-bit and 64-bit architecture.

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