Ike Naar wrote:
> In article <0.c56050528d2e8563dbcd.20100820020535BST.8762z65c >,
> Ben Bacarisse <> wrote:
>> (Ike Naar) writes:
>>> Now in the following expression:
>>>
>>> g(x) + h(y);
>>>
>>> are g and h allowed to run simultaneously?
>> No, not in any meaningful sense. Execution proceeds as defined by the C
>> abstract machine and that defines only one locus of execution that moves
>> through the code (my words but one can find supporting text).
>
> That's what I thought, too, but I can't seem to find the supporting text.
> One thing that comes close is in the "Storage durations of objects"
> chapter: "Calling a function that returns suspends but does not end
> execution of the block containing the call.". Is that it?
C1X has "unsequenced" (could even be simultaneous) versus
"indeterminately sequenced", if that helps.
Experience suggests that two reads of a 'volatile' object do not happen
at the same time, but one after the other. C99 allows the
implementation to choose if:
volatile int x = 1;
x = x + x;
is one read or two.
Similarly, that bit from C99 about an outer function's execution being
suspended while in an inner function is congruent with C1X's definition
for called functions being indeterminately sequenced with regards to any
peer evaluations; those peers are evaluated before or after, but not during.
Even if that bit from C99 about an outer function's execution being
suspended while in an inner function is true, perhaps there is something
more which specifies that your 'g' and 'h' cannot be called at exactly
the same time... If they were, that would still mean the outer
function's execution is suspended. If you find the relevant text in the
Standard, it will help to suggest (along with "real-world" 'volatile',
perhaps) that:
Evaluations of expressions have a [specified or unspecified] linear order.
(The above is not a quote.)
Isn't it nice that '++a' is such a trivial thing that it could be
evaluated concurrently with a read of 'b', but a 'g' function call
doesn't seem to enjoy the same treatment, no matter how trivial the body
of 'g' might be? 'volatile' (in the "real" world, perhaps) and function
calls thus allow the programmer a bit of control by making things
somewhat atomic.