Microsoft KB Archive/47969
INF: Sample PM Program That Frees Stacks at Thread Termination PSS ID Number: Q47969 Article last modified on 09-06-1991 PSS database name: P_PresMan
The Presentation Manager (PM) sample program THRDSTCK, located in the Software/Data Library, shows how to have a thread create its stack and free it just before exiting. This avoids having to use another thread blocking on a semaphore to destroy the stack. The threads in this sample program switch to another temporary stack, free the main stack, and then exit.
The sample program is written to use both the DOS and the C multithreaded run-time thread and memory-management routines. The DOS versions are faster and simpler; however, the C versions must be used if other C run-time routines are going to be used.
THRDSTCK also shows a method using DosGetPrty() to delay exiting the main thread until after the other threads have exited. It also traps SIG_KILLPROCESS to ensure that it can make an orderly exit when killed from a windowed command shell.
The sample program shows some problems with background threads under version 1.21 and some possible solutions.
Please refer to MTDYNA.DOC included with version 5.10 of the Microsoft C Compiler for further details on writing multithreaded applications.
THRDSTCK can be found in the Software/Data Library by searching on the word THRDSTCK, the Q number of this article, or S12371. THRDSTCK was archived using the PKware file-compression utility.
Additional reference words: G891003-87 1.1
Copyright Microsoft Corporation 1991.