gracefull NT thread termination upon signal
Posted on 1997-08-28
This problem affects NT4.0 (with Watcom 10.6 but should be compiler independent).
Here is the question: How to terminate a thread gracefully by cleaning up the stack instead of having a growing stack, e.g. by use of TerminateThread(hdl).
All our attempts to terminate a thread other than letting EndThread()initiating the return to the call lead to a growing overall memory consumption of the application. The disadvantage of EndTread() is that it can´t be used directly to terminate the thread from outside.
The only awkward solution that we additionally fear would be to use something like a flag that would have to be polled frequently.
Our approach to test is: malloc for the stack of a thread and to pass the pointer received from malloc within BeginTread(), alternatively calling BeginThread and feeding Zeros as arguments only. The thread itself does a simple delay (for test purposes), nothing else. Now we tested 2 options:
1) let the thread terminate normally without any signal
2) terminate by use of TerminateThread()
Option 1 seems to be ok, option 2 causes a increase in memory allocation (although freeing the malloced memory if necessary).
We know that signalling is poor under NT but is it really so poor that there is no solution? How is the rest of the NT programmers solving this kind of problem?