MF 

The WAIT Statement

The WAIT statement suspends execution until an event is TRUE.

General Formats for Format 1 (Thread)


*

General Formats for Format 2 (Event)


*

Syntax Rules for Format 1 (Thread)

  1. Thread-pointer-1 must be defined as USAGE THREAD-POINTER.
  2. Identifier-1 must be defined either as USAGE POINTER or must be four bytes in size. It must not be a function-identifier.
  3. Identifier-2 must be defined as an integer data item that has a length of at least four digits.

Syntax Rules for Format 2 (Event)

  1. Event-pointer-1 must be defined as USAGE EVENT-POINTER.

General Rules for Format 1 (Thread)

  1. Thread-pointer-1 must contain a thread handle as returned from the START statement with the IDENTIFIED BY phrase or from a CBL_THREAD_ library routine.
  2. A successful WAIT statement suspends the current thread's execution until the termination of the thread referenced by the thread handle contained in thread-pointer-1.
  3. If the RETURNING phrase is specified, a successful WAIT statement returns a value in identifier-1.
  4. After the successful execution of a WAIT statement, the thread handle contained in thread-pointer-1 is invalid.
  5. If the STATUS phrase is specified, the execution of the WAIT statement places into identifier-4 one of the return codes specified for the CBL_THREAD_ library routines.
  6. If the WAIT statement fails, one of the return codes specified for the CBL_THREAD_ library routines is placed into identifier-2, if specified, and then one of the following occurs:
    1. If the ON EXCEPTION phrase is specified, control is transferred to imperative-statement-1. Execution then continues according to the rules for each statement specified in imperative-statement-1. If a procedure-branching or conditional statement that causes explicit transfer of control is executed, control is transferred in accordance with the rules of that statement; otherwise, upon completion of the execution of imperative-statement-1, control is transferred to the end of the WAIT statement and the NOT ON EXCEPTION phrase, if specified, is ignored.
    2. Otherwise, if the NOT ON EXCEPTION phrase or the STATUS phrase is specified, control is transferred to the end of the WAIT statement and the NOT ON EXCEPTION phrase, if specified, is ignored.
    3. Otherwise, the run unit terminates with a run-time system error.
  7. If the WAIT verb is successful, the following occurs in the order specified:
    1. If the STATUS phrase, is specified, ZERO is moved to identifier-2.
    2. If the NOT ON EXCEPTION phrase is specified, control is transferred to imperative-statement-2. Execution then continues according to the rules for each statement specified in imperative-statement-2. If a procedure-branching or conditional statement that causes explicit transfer of control is executed, control is transferred in accordance with the rules of that statement; otherwise, upon completion of the execution of imperative-statement-2, control is transferred to the end of the WAIT statement and the ON EXCEPTION phrase, if specified, is ignored.

General Rules for Format 2 (Event)

  1. A successful WAIT statement suspends execution until the event referenced by event-pointer-1 is TRUE.
    Note: Execution resumes immediately if the event referenced by event-pointer-1 is TRUE when the statement is executed.
  2. If the WAIT statement fails, the run unit terminates with a run-time system error.