15.2.4.4 CRITICAL SECTION Directive (TU*X only)

The CRITICAL SECTION directive restricts access to a block of code to only one thread at a time. It takes the following form:

c$PAR CRITICAL SECTION [(latch-var)]
      block
c$PAR END CRITICAL SECTION


c
Is one of the following: C (or c), !, or * (see Section 15.2.1).


latch-var
Is a naturally aligned INTEGER(4) or INTEGER(8) SHARED variable.


block
Is one or more statements or constructs. You cannot branch into or out of the block.

Rules and Behavior

Critical sections can appear anywhere an executable Compaq Fortran statement can appear.

You can use a latch variable to control whether multiple critical sections have unique latches or use the same latch. If a latch variable name is used, the program must explicitly initialize the latch variable to zero before any CRITICAL SECTION using that latch variable is executed.

If you do not specify a latch variable, the compiler supplies a unique latch for each critical section.

A thread waits at the beginning of a critical section until no other thread in the team is executing a critical section having the same latch variable name. When the thread that is executing the critical section reaches the END CRITICAL SECTION directive, the latch variable is set to 1, allowing another thread to enter the critical section.

The program must not reuse that latch variable in anything other than a CRITICAL SECTION until all uses as a latch variable are complete.

All unnamed critical sections map to the same latch variable name supplied by the compiler. Critical section latch variable names are global to the program.


Previous Page Next Page Table of Contents