Using a Termination Handler

The following example shows how a termination handler is used to ensure that resources are released when execution of a guarded body of code terminates. In this case, a thread uses the
EnterCriticalSection function to wait for ownership of a critical section object. When the thread is finished executing the code that is protected by the critical section, it must call the
LeaveCriticalSection function to make the critical section object available to other threads. Using a termination handler guarantees that this will happen. For more information, see
critical section objects.