The DllMain entry point is pretty much designed for this purpose and
works in all versions of Windows that support threads. This is the
technique used by pthreads-win32. But it only works for DLLs.
For static linking into executables, there is a special table of
function pointers that are called by the runtime in pretty much the
same situations as DllMain. This apparently works starting around
Windows XP timeframe, and is the technique used by libwinpthread.
We combine both techniques so at least the DLL cleanup works even
on very old versions of Windows. The static library cleanup will
work on contemporary versions.
To test this, we need to restructure the thread test program to link
against a real (uninstalled) DLL with the test entry points.