Occasionally, an MS-DOS driver or TSR program may need to run for a period
of time that may exceed its regular time slice. In such cases, the driver can create
a critical section that prevents Windows from switching the CPU away from the driver or program.
A driver starts a critical section by using Begin Critical Section (Interrupt 2Fh Function 1681h). While the critical section is in effect, only device interrupts can divert execution from the driver. A driver ends the critical section by using End Critical Section (Interrupt 2Fh Function 1682h). In general, a driver should end the critical section as soon as possible to ensure that all drivers and programs in the system receive CPU time. If a driver starts a critical section n times, it must end the critical section n times before the critical section is actually released.
Ordinarily, Windows prevents rescheduling of the current virtual machine if the one-byte, MS-DOS InDOS flag is nonzero. One exception is when a driver or program issues the MS-DOS Idle interrupt (Interrupt 28h). In such cases, Windows
may reschedule regardless of the value of the InDOS flag. The only way to prevent this rescheduling is to start a critical section using Begin Critical Section. While in a critical section, Windows disregards Interrupt 28h.
In previous versions of Windows (for example, Windows/386Ô version 2.x), service functions to support critical sections were not supplied. Drivers and programs achieved a similar effect by incrementing and decrementing the MS-DOS InDOS flag. Although this method was acceptable for previous versions of Windows, drivers should not use this method in versions of Windows that supply Begin Critical Section and End Critical Section (Interrupt 2Fh Function 1682h).
Drivers and programs that use the InDOS flag method retrieve the address of the InDOS flag using Get InDOS Flag Address (Interrupt 21h Function 34h). The function returns the address in the ES:BX register pair. When using this method, drivers and programs check the flag value before decrementing because some error conditions (such as when the user types CTRL+C) set the InDOS flag to zero regardless of its current value. Decrementing the InDOS flag to a number less than zero is a serious error.