How 4Test Handles Script Deadlock

It is possible for a multi-threaded 4Test script to reach a state in which competing threads block one another, so that the script cannot continue. This is called a script deadlock. When the 4Test runtime environment detects a deadlock, it raises an exception and halts the deadlocked script.

Example

The following script will never exit successfully.
share INTEGER iIndex1 = 0
share INTEGER iIndex2 = 0

main ()
  parallel
    access iIndex1
      Sleep (1)
        access iIndex2
          Print ("Accessed iIndex1 and iIndex2")
    access iIndex2
      Sleep (1)
        access iIndex1
          Print ("Accessed iIndex2 and iIndex1")