Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

ATOMIC_CAS

Atomic Intrinsic Subroutine (Generic): Performs atomic compare and swap.

CALL ATOMIC_CAS (atom, old, compare, new [, stat])

atom

(Input; output) Must be a scalar coarray or coindexed object and of type integer with kind ATOMIC_INT_KIND or type logical with kind ATOMIC_LOGICAL_KIND. atom becomes undefined if an error occurs. Otherwise, if atom is of type integer and equal to compare, or of type logical and equivalent to compare, it becomes defined with the value new. If atom is of type logical and has been assigned a value other than .true. or .false., the result is undefined.

ATOMIC_INT_KIND and ATOMIC_LOGICAL_KIND are named constants in the intrinsic module ISO_FORTRAN_ENV.

old

(Output) Must be a scalar of the same type as atom. It becomes undefined if an error occurs. Otherwise, it becomes defined with the value atom has at the beginning of the atomic operation.

compare

(Input) Must be scalar and the same type and kind as atom.

new

(Input) Must be scalar and the same type and kind as atom.

stat

(Output; optional) Must be a non-coindexed integer scalar with a decimal exponent range of at least four (KIND=2 or greater). The value assigned to stat is specified in Overview of Atomic Subroutines. If stat is not present and an error condition occurs, error termination is initiated.

Example

Consider the following:

CALL ATOMIC_CAS (N[4], I, 8, 10) 

If the value of N on image 4 is 8 when the atomic operation is initiated, N on image 4 is defined with the value 10, and I is defined with the value 8 when the operation is complete and no error occurs during the subroutine reference. If the value N on image 4 is 13 when the atomic operation is initiated, the value of N is unchanged, and the value of I is 13 when the operation completes and no error condition occurs during the procedure reference.