> To guarantee that you've observed the store to "i", you HAVE to read
> the store to "j" first! Plus, your second "for" loop could have blocked
> just after reading "i" into "a", while the first loop could be continuing
> to count upward. "b" could end up with an arbitrarily larger value.
>
> To make this work correctly in the face of both Processor Ordering
> and pauses in the process execution, the second loop should actually say:
>
> for (;;) {
> b = j;
> a = i;
> if (a < b)
> BUG();
> }
Don't be confused when this too eventually breaks when tested.
The counters will wrap, i slightly before j, and that may trigger the
BUG().
For a safe test, change the first loop to:
i = j = 0;
for (;;) {
i++;
j++;
if (i == 0x7FFFFFFF) {
j = 0;
i = 0;
}
Helge Hafting
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/