The CRITICAL SECTION directive restricts access to a block of code to only one thread at a time. It takes the following form:
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.