(j3.2006) (SC22WG5.3705) [ukfortran] Atomic stuff

N.M. Maclaren nmm1
Wed Dec 3 04:52:33 EST 2008


On Dec 3 2008, Van Snyder wrote:
>
>I can think of three ways that I would prefer to the intrinsic
>subroutines described in 08-297r1.
>
>1.  Provide an attribute for a variable that says accesses to it are
>atomic.  This seems to have been the intent of the use of VOLATILE in
>08-007r2:Note 8.28.  One might desire to enclose the declaration and
>access within a BLOCK, so the attribute would work like ASYNCHRONOUS in
>that respect: a declaration of the attribute within a BLOCK isn't a
>declaration of a new variable.

The killer here is Fortran's expression evaluation model, which is why
VOLATILE is so toxic.  As Fortran is specified, variable references have
essentially the same properties as function calls - i.e. in an arbitrary
order and a compiler may omit any it can deduce the value of in other ways.
VOLATILE provides a hand-waving exception to this, but %deity alone knows
exactly what it means in any language that has it.

Now, it would be possible to add a restriction that there is only one 
atomic access per statement, but that is probably too restrictive. However, 
if that is not done, the effects are completely unpredictable unless 
Fortran starts to define the ordering semantics of expression evaluation.

Yes, the intent is clear for all trivial examples, but inexperienced and
'too clever by half' programmers will go beyond those and the standard needs
to specify where defined behaviour stops.  I have spent a LOT of time trying
to explain to both experienced users and Tier 1 vendors exactly what the C
standard specifies (and doesn't), and should prefer that Fortran maintains
its currently better-defined state.

>Other cases, such as appearing in an I/O list, are obvious in all three
>methods, and impossible with the intrinsic subroutine method.

Yes.  And that is precisely why the subroutine method is better.  Firstly,
we would need to define or exclude the effect of asynchronous I/O with
atomic variables!

Secondly, and more seriously, atomic accesses will need some sort of an
inter-image handshake on most systems - even most SMP systems often need
extra instructions to synchronise the memory subsystem.  And, currently,
Fortran does not require any inter-image communication in the middle of
expressions - everything is done at the statement level, which has at least
a defined serial ordering.

>Actually, I would prefer a much higher level concept, ...

Agreed, but as Malcolm said ....


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1 at cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679




More information about the J3 mailing list