Mingw32 : issue with atexit function in main thread
I have this C - program that uses a dll library of my own, originally
created on a Linux platform.
This DLL library creates some internal threads. The main program does
not know of the existence of these threads.
To cleanup these threads (and other resources), the current
implementation of that library registers a cleanup function using the
atexit C function.
The idea is that when the program returns from main after it has
finished doing its business, the library gets the last word to do its
own cleanup work.
What happens in Mingw is that the internal threads is still alive just
before the return from main but somewhere between
the return and the call of atexit cleanup function, the threads are stopped.
I checked the source code of pthread and I think it has something to
do with the pthread_win32_process_detach_np function that gets
executed when the pthread dll gets unloaded ( or something like that).
Is there any way I can reproduce get the atexit behavior i.e. that the
cleanup function gets called *before* the threads
are terminated by the pthread dll ?
Or is there another (non portable ?) way I can register a cleanup
function to the mingw specific pthread implementation by not using
atexit but something else ?