Thread Pausing

There are some conditions in which all of the threads in your program will pause. One reason this occurs is when some event in the system causes the entire runtime to suspend. The pause ends when the runtime regains control. The main cases where this occurs are:

  1. when moving any of the application's windows with the mouse. The host system manages this task.
  2. when a message box is displayed (by calling the MESSAGE utility program or DISPLAY MESSAGE BOX). The message box is managed by the host system. You can use this to your advantage by using message boxes to report critical errors. The message box requires that the user respond to the box before any part of the application will resume.

Although the host system does not handle these tasks in character-based versions of the runtime, architectural similarities between the character and graphical versions cause these tasks to produce the same effect on character systems.

Another reason for all threads in your multithread program to pause is waiting for locked records. You can configure the runtime to automatically wait for locked records by either setting the WAIT-FOR-LOCKS configuration option, or by compiling with the RM/COBOL compatibility (-cr option) and omitting a declarative for this particular file. When you do this in a multi-threaded program, all threads are frozen while waiting for a locked record to unlock. This occurs because the runtime employs a very tight wait loop that does not allow other threads to continue running.

Note: You can avoid this by writing your own wait loop. Simply turn off the runtime option and perform the affected file operations in a loop until the file status is not 99. For efficiency, we recommend calling C$SLEEP for at least one second between file operations when waiting for a lock.