CRITICAL construct

Standard: F77 F90 F95 F2003 F2008 F2018 Example program


<Syntax>

critical-stmt
      block

end-critical-stmt

critical-stmt ::= [ construct-name : ] CRITICAL [ ( [ sync-stat-list ] ) ]
sync-stat-list ::= sync-stat [ , sync-stat ]
sync-stat ::= STAT = stat-variable | ERRMSG = errmsg-variable

end-critical-stmt ::= END CRITICAL [ construct-name ]

If the CRITICAL statement has a construct name, the END CRITICAL must have the same construct name. The construct name has no effect on execution of the construct.

A stat-variable must be a non-coindexed scalar Integer variable, and should be able to represent values from −9999 to +9999. An errmsg-variable must be a non-coindexed scalar Character variable with default kind.

The block is not permitted to contain a RETURN statement, an image control statement, or a branch to a statement outside the construct. Thus, the only means of exiting a CRITICAL construct is through execution of the END CRITICAL statement.

A CRITICAL construct can invoke a procedure that is not pure, but the invoked procedure is not allowed to execute an image control statement.

<Semantics>

A CRITICAL construct is only executed by one image at a time; that is, if another image is already executing the construct, execution of the CRITICAL statement delays until that image executes the END CRITICAL statement.

Note that CRITICAL constructs cannot be nested (because the CRITICAL statement is an image control statement); this means that a valid program cannot deadlock due to use of CRITICAL.

If the STAT= specifier appears in a CRITICAL statement, stat-variable is assigned the value zero if no error occurs, and a positive value otherwise. If stat-variable is assigned the value of STAT_FAILED_IMAGE (from ISO_FORTRAN_ENV), it means that the preceding image failed whilst executing the CRITICAL construct (and that this image is now the only image executing inside the CRITICAL construct). If an error occurs but STAT= does not appear, the program is terminated. If ERRMSG= appears and an error occurs, errmsg-variable is assigned an explanatory message; otherwise, errmsg-variable is unchanged.

<Related>

END CRITICAL statement, ERRMSG= specifier, Image control statements, STAT= specifier