(j3.2006) Public Comment J32034

Jim Giles JamesGiles-2
Tue Jul 15 18:02:16 EDT 2008

Aleksandar Donev wrote:
>> Instead of a CRITICAL construct, I think that CRITICAL
>> should be a keyword like PURE or RECURSIVE (and such) that
>> applied to procedure declarations.  Similarly, it should
>> be an optional keyword on the new BLOCK construct:
>> block-stmt is [ block-construct-name : ] [ CRITICAL ] BLOCK
> Or, how about
>    declare local entities

Actually, for reasons given later,  the idiom is more likely to be:

         declare local entities

> Why is merging the two blocks better? The only thing I can think of is
> that the stack will not be grown if another image is already executing
> the block. Is this the point?

It's more legible.  It more clearly indicates the coincidence
of the scoping and the critical section.  It's for improved
user productivity.  It also reduces the proliferation of
multiple different kinds of block-constructs, which
simplifies the language for old and new users alike.

> There may be some issues here about the fact that it is not
> well-defined when execution of declarations (example, allocation,
> evaluation of specification expressions, etc.) occurs, so saying a
> CRITICAL BLOCK or SUBROUTINES cannot begin execution if another one
> is already executing one might be ambiguous and cause undefined
> behavior. For example:
> INTEGER :: N=0
>   REAL :: A(N)
>   N=N+1
> Does each image get a local array A of a different size (one larger
> every time the critical block is executed)?

Exactly the kind of example I was thinking of.  With *alex's* nesting
(from above, with the CRITICAL after the declarations) this is really
nasty.  If the variable N is really shared the meaning is difficult to
fathom.  Several instances of the BLOCK might have the same value
of N  - or they might not.  It's completely unpredictable.  If N is really
shared, then all uses of N should be inside the CRITICAL section - including
*especially* the declarations that use N in specification expressions.

If N isn't shared there's no reason for the above to be a critical
block anyway.

Oh, and by the way, CRITICAL is a property (like PURE or RECURSIVE
as applied to procedures): the construct is still a BLOCK construct.  The
correct END statement is END BLOCK.  That's what was intended anyway.

J. Giles 

More information about the J3 mailing list