The Old New Thing

If you want to track whether the current thread owns a critical section, you can use the critical section itself to protect it

You may find yourself in the situation where you want to keep track of the owner of a critical section. This is usually for debugging or diagnostic purposes. For example, a particular function may have as a prerequisite that a particular critical section is held, and you want to assert this so that you can catch the problem when running the ...