Re: working draft C++, program model
Hello Ganesh,
3) you spotted a case where the ambiguity described in the note could
occur in a single thread, so it can't constitute a data race, although
the behaviour is undefined anyway.
BTW, this renders the note, as it is, simply logically false.
If the note in 1.10/12 was worded this way:
"Note: If there is ambiguity about which side effect to a non-atomic
object is visible then the behavior is undefined."
would that be clearer to you?
Better, yes, but good enough?
I asked myself, what problem did the authors of the draft address in their note
in 1.10/12. Essentially I read it as follows:
"Trust our concept of 'visible side effect', because
switch(situation){
case data race:
admittedly ambiguous;
so concept cannot apply, but program is undefined anyway; break;
default:
fine here, you can always determine a unique visible side effect;
}"
But the enumeration of cases was not complete, they missed at least one:
unsequenced side effects. That was part of the content of my original post.
Now you want to apply a simple hot fix, which creates the following situation:
"Trust our concept of 'visible side effect', because
switch(situation){
case unsequenced:
case data race:
admittedly ambiguous, but program is undefined anyway; break;
default:
fine here, you can always determine a unique visible side effect;
}"
But what makes you think, you have covered all relevant cases now?? As an example,
let me introduce another difficult one, indeterminately sequenced side effects:
The following code snippet is based on one from a mail I received privately in
the course of this thread:
int i = 0;
int f(){
return ++i; // side effect A
}
int g(){
return i*=2; // side effect B
}
int h(int, int){
return i; // value computation C
}
int main(){
return h(f(),g()); // function call D, returns 1 or 2?
}
f and g are invoked indeterminately sequenced, so A and B are indeterminately
sequenced side effects on i as well (the evaluation order of arguments in D is
unsequenced).
If we can agree, perhaps in the light of the note in 1.9/16, that it constitutes
an ambiguity here, not knowing, whether A or B is the visible side effect on C,
you may see that this might again affect the argumentation of the draft's authors.
"Trust our concept of 'visible side effect', because
switch(situation){
case indeterminately sequenced:
defined behavior, yet possibly ambiguous;
concept does not always apply; break;
case unsequenced:
case data race:
admittedly ambiguous, but program is undefined anyway; break;
default:
fine here, you can always determine a unique visible side effect;
}"
Note that your revision of 1.10/12 doesn't hold here any more.
And even if you can fix this one, you'll have to make sure, there is no other
exceptional case left uncaught!
Given that it's a *non-normative* note, I don't think such a change
would have any impact to the overall wording.
I need of more clarification, before I can agree to that.
Wolf Lammen
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]