Claiming Critical Sections on Timer Ticks

Last reviewed: April 12, 1995
Article ID: Q100579
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows, version 3.1

SYMPTOMS

A deadlock situation in which the system is apparently frozen but the mouse still moves on the screen.

CAUSE

Claiming a critical section from inside a timer (IRQ 0) interrupt handler may cause a deadlock in the following scenario:

  1. Virtual machine (VM) A claims the critical section.
2. VM B receives a virtual timer interrupt, tries to claim the critical
   section itself, and gets suspended.
3. VM A waits on a timer tick before it releases the critical section,
   but will no longer see timer interrupts. This deadlocks the machine.

Note that it is not uncommon for global terminate-and-stay-resident (TSR) programs to wait for timer interrupts to occur before resuming execution; in particular, many network drivers use this technique to periodically retry unsuccessful packet transmissions.

WORKAROUND

The workaround for this problem is to use the documented TimerCriticalSection entry in SYSTEM.INI, which will implicitly wrap the virtual interrupt into a critical section.

Alternatively, application code could call into a VxD to obtain the critical section status (using the Get_Crit_Sect_Status service) before attempting to claim the critical section in a timer tick.

MORE INFORMATION

VM A no longer receives timer interrupts in the above scenario because the virtual timer device (VTD) sets the V86 interrupt vector of each virtual machine to a small code stub that filters out certain timer interrupts. In particular, the code stub does not allow nested timer interrupts to be reflected into the same virtual machine. Thus, virtual machine B has a pending timer interrupt, and therefore, virtual machine A does not receive any timer interrupts but does not release the critical section because it waits for a timer interrupt, while VM B does not finish processing the timer interrupt because it is suspended on the critical section. This scenario will deadlock the two processes.


Additional reference words: 3.10
KBCategory: kbprg
KBSubcategory: D3MiscVTD


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 12, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.