TLS flushing is usually done in DllMain when it is passed DLL_THREAD_DETACH.
If your code is in an EXE, and not in a DLL, you can create a dummy DLL loaded by the EXE, which in turn will call the DLL_THREAD_DETACH into the EXE. (I do not know how best to work with the EXE code at the end of the stream.)
There are several ways that a DLL can call back to an EXE: one of them is that the EXE can export functions like DLLs, and the DLL can use GetProcAddress to handle the EXE module. An easier way is to provide the DLL with an init function that the EXE calls to explicitly pass the function pointer.
, , DllMain, (, , ), , . ; , API kernel32.dll, HeapAlloc, TLS.
, DLL_THREAD_ATTACH , , DLL ( DLL_THREAD_DETACH, DLL), () DLL_PROCESS_DETACH, .