Critical Sections

The OS/2 and Windows operating systems support the use of critical sections to mark particular sections of code that should never be timesliced out within a multithreaded application. The purpose of these critical sections is to prevent problems such as loss of data integrity (where two threads are simultaneously reading and then writing to the same variable or file). You should avoid using critical sections except under very limited circumstances. Critical sections can cause deadlocks and major timing problems, because:

Semaphores and critical sections provide some of the same functionality, but using only semaphores is a better programming practice and leads to more threadsafe programs. Avoid the use of critical sections in your programs wherever possible.



Debugging Threads