Protecting Nonreentrant Code of a Process

Because the global data of a process is shared among all threads, care must be taken to avoid conflicts in data access that could result in program failure. One of the features Win32 provides to protect nonreentrant code is the critical section object. A critical section is an object used only for synchronization of the threads of a single process. The InitializeCriticalSection function creates a critical section object.

After the critical section object is constructed, a thread must use the API function EnterCriticalSection to gain exclusive access to the protected code. If another thread is executing within the critical section, a thread requesting access to the critical section must wait until the ...

Get Microsoft Windows 2000 API SuperBible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.