To: J3 09-184 From: Aleksandar Donev and Bill Long Subject: Atomic compare-and-swap Date: 2009 April 08 Discussion: --------- Several people external to WG5, and several members of the committee, have proposed that in addition to ATOMIC_DEFINE and ATOMIC_REF it is very useful to add an atomic read-modify-write intrinsic. The most basic of those in both theoretical works and also practical implementations is the atomic compare-and-swap (CAS) intrinisc. This paper proposes to add this to the current draft. The basic operation of this intrinsic is: atomic_cas (atom, old, compare, new) which performs atomically: old = atom if (old == compare) atom = new Edits: --------- [323:Table13.1] In Table 13.1 Standard generic intrinsic procedure summary, add a new entry "ATOMIC_CAS (ATOM, OLD, COMPARE, NEW) A Conditionally swap values atomically." [335:6+] Following 13.7.19 ATANH (X) add a new intrinsic: "13.7.19a ATOMIC_CAS (ATOM, OLD, COMPARE, NEW) Description. Conditionally swap values atomically. Class. Atomic subroutine. Arguments. ATOM shall be scalar and of type integer with kind ATOMIC_INT_KIND or of type logical with kind ATOMIC_LOGICAL_KIND, where ATOMIC_INT_KIND and ATOMIC_LOGICAL_KIND are the named constants in the intrinsic module ISO_FORTRAN_ENV. It is an INTENT (INOUT) argument. If the value of ATOM is equal to the value of COMPARE, ATOM becomes defined with the value of INT (NEW, ATOMIC_INT_KIND) if it is of type integer, and with the value of NEW if it of type logical. OLD shall be scalar and of the same type as ATOM. It is an INTENT (OUT) argument. It becomes defined with the value of INT (ATOMC, KIND (OLD)) if ATOM is of type integer, and the value of ATOMC if ATOM is of type logical, where ATOMC has the same type and KIND as ATOM and has the value of ATOM used for the compare operation. COMPARE shall be scalar and of the same type and kind as ATOM. It is an INTENT(IN) argument. NEW shall be scalar and of the same type as ATOM. It is an INTENT(IN) argument. Example. CALL ATOMIC_CAS(I[3], OLD, Z, 1) causes I on image 3 to become defined with the value 1 if its value is that of Z, and OLD to become defined with the value of I on image 3 prior to the comparison."