Initialize Critical Section only once for a process

On Windows Vista you can use the one-time initialization functions. Using One-Time Initialization shows how to use them to make sure an event is initialized only once.


I'd suggest wrapping the CRITICAL_SECTION with a class that will handle the initialization and uninitialization of the critical section object in its constructor and destructor. This way, you'll be thread safe in most cases. (You'll have to make sure no one accesses the object before its constructor completes, but that's relatively easy.)

There are several common wrappers for CRITICAL_SECTION you can use. MFC's CCriticalSection is the obvious choice, but you can create your own as well.