Subj : Re: winXP/2k: ExitProcess() & atexit with multiple threads? To : comp.programming.threads From : m_pll Date : Sun Feb 20 2005 09:32 pm Are you running exact same code in both cases? As far as I know there should be no changes with regard to ExitProcess behavior between 2000 and XP. What CRT version are you using (static or DLL, multithreaded or not, what compiler version)? ExitProcess does not know anything about CRT exit handlers. All it does is kill all remaining threads except the current one and then call DllMain(PROCESS_DETACH) for all loaded DLLs. So atexit handlers (as well as static destructors) will only be called if you do one of the following: a) return from main() b) call exit() explicitly c) link to the DLL version of CRT (/MD) (or if you link statically but your module is a DLL). In this case the CRT provided DllMain will invoke exit handlers, even if somebody calls ExitProcess. Normally, you should exit all your worker threads then return from main. You should also avoid doing anything non-trivial in exit handlers, static destructors or DllMain. Mile Blenton wrote: > Recently I've come accross the following behavior when using > ExitProcess() inside addional thread I create within my prg. > > In main thread I attach a function to be called on exit with > atexit() and create an additional thread with CreateThread(). > At some point inside created thread ExitProcess() is called. > > Under winXP (with and without SP1, did not test with SP2), > user atexit function gets called within context of the > running thread (in this case it's the additional thread from > where ExitProcess() is called). > > Under win2000 this is not the case, user atexit function will > not be called when created thread calls ExitProcess, it only > get's called when main thread terminates or calls ExitProcess > (or so it would seem from my test prg). > > > Anyone noticed this and has any explanation of this behavior? > Which beahvior is the right one? > ...or is it just another win wysiwyg feature and should be > accepted as such? :) .