views:

64

answers:

1

I have a mixed-mode executable and I noticed that the constructor of my native global variables is called in the main thread, but the destructor is called in some other thread.
The name of thread is 'Thread::intermediateThreadProc'.

The global variables are

What is the reason for this? And what is this 'Thread::intermediateThreadProc' thread?

Thanks.

+2  A: 

Thread::intermediateThreadProc() is a little helper function in the CLR that's used as the thread start function for any thread started by the CLR. Find it back in the SSCLI20 source, src\vm\threads.cpp

Seeing this run on another thread is to be expected. Cleanup code runs when the appdomain gets unloaded. The CLR logic for it is mighty complicated, but it looks like it will run when the appdomain runs the finalizer thread for the last time to clean up the heap. You can assume that all managed objects are dead and there are no other threads running. Beware that your code is subject to the two second finalizer thread timeout.

Hans Passant
nice answer. thanks!
eli