Pete Becker
10/26/2008 5:47:00 PM
On 2008-10-26 12:49:12 -0400, "wolf.lammen" <wolf.lammen@googlemail.com> said:
> Hi,
>
> I had a look at the program model of the current working draft of C++
> and stumbled over a phrase, that looks to me incorrect.
>
> The first note in 1.10 paragraph 12 states:
> "Note: If there is ambiguity about which side effect to a non-atomic
> object is visible, then there is a data race, and the behavior is
> undefined."
>
> That's not exact, because two unsequenced side effects may cause an
> ambiguity
> as well.
>
> Consider the following code snippet
>
> int i = 0;
> i = // side effect A
> i++ // side effect B
> + 1;
> if (i == 1)... // value computation C
>
> Since the A and B are unsequenced, both are visible side effects to C.
> But this ambiguity does not constitute a data race, because A, B, C
> are
> executed in the same thread.
There's no ambiguity here. The behavior is undefined, under 1.9/16.
While the words in that note could be changed to talk about side
effects from multiple threads, that would be more complicated to say.
As it is, it's a bit informal, but I think it's sufficiently clear for
a note in a section that's explicitly talking about multi-threaded
executions.
Don't forget, notes are not normative. That is, they do not impose
requirements. Think of them as comments in code: comments help guide
you, but they don't affect what the code does; similarly, notes help
guide you through the standard, but they don't affect its meaning.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)