When I write C/C++ code for Windows platform, I usually use Windows APIs as necessary. But when it comes to multi-threading, I read the following quotaion from < Windows via C/C++ >
The CreateThread function is the
Windows function that creates a thread.
However, if you are writing C/C++
code, you should never call
CreateThread. Instead, you should use
the Microsoft C++ run-time library
function _beginthreadex. If you do not
use Microsoft’s C++ compiler, your
compiler vendor will have its own
alternative to CrateThread. Whatever
this alternative is, you must use it.
AFAIK, a language run-time library for a certain platform is implemented with that platform’s APIs. I think it is totally possible to call CreateThread() from my C/C++ code. And I quite did that. But I just don’t understand why the above rule should be followed.
Many thanks for your insights.
Of course it’s possible to use the Windows API’s
CreateThreaddirectly.But that leaves the runtime library uninformed about the new thread.
For the multi-threading support in the runtime library (and that includes functions that rely on static storage, e.g. I imagine it includes
strtok) you need to keep the runtime library informed, and not only informed, but partially in charge so that e.g. failure to allocate whatever resources it needs for a thread, results in thread creation failure.Cheers & hth.,