了解并发程序中的 At-Most-Once-属性
Understanding the At-Most-Once-Property in a concurrent program
我正在尝试理解最多一次 属性 其中指出:
赋值语句 x = e 的一个属性,其中 (1) x 未被另一个进程读取并且 e 最多包含一个对被另一个进程更改的变量的引用,或者 (2) x 未被写入由另一个进程和 e 不包含对由其他进程更改的变量的引用。
int x = 0, y = 0;
co x = x+1; // y= y=1; oc;
满足属性因为x没有被第二个进程读取并且没有临界区
int x = 1, y = 1;
co <x = x + y;>
// y = 0;
// x = x - y;
oc
虽然我不明白这个程序如何满足 属性。第一条语句是原子语句,所以它无论如何都无效,但是 y=0 会影响第三条语句 x 结果,所以我不明白这是如何满足 属性?
我想知道这可能意味着什么......那是一个特别潮湿的下午,我去看看发现:
At-Most-Once Property
Andrews defined a condition called at-most-once under which expression evaluations and assignments will appear to be atomic.
A critical reference in an expression is a reference to a variable that is changed by another thread.
An assignment statement x = e
satisfies the at-most-once property if either:
1.1: e
contains at most one critical reference and x
is neither read nor written by another thread, or
1.2: e
contains no critical references, in which case x
may be read or written by other threads.
An expression that is not in an assignment satisfies at-most-once property if it contains no more than one critical reference.
This condition is called at-most-once because there can be at most one shared variable, and the shared variable can be referenced at most one time. ...
我认为你的谜题的关键是这句话:
... Assignment statements that satisfy at-most-once property appear to execute atomically even though they are not atomic.
和
... That is, we would get the same results from executing these assignment statements even if we were to somehow prevent the interleaving of their machine instructions so that the assignment statements were forced to execute atomically.
假设我理解正确:
<x = x + y;>
是原子读-修改-写。所以这已经是原子的——它不需要 "appear to execute atomically".
y = 0
是 最多一次 所以满足上面的 (1.2) 并且会 "appear to execute atomically"。因为它确实...
...这意味着 x = x - y
也是 最多一次
……我觉得。 (当您找到明确的答案时,请告诉我们。)
很好奇这个有什么用!
我正在尝试理解最多一次 属性 其中指出:
赋值语句 x = e 的一个属性,其中 (1) x 未被另一个进程读取并且 e 最多包含一个对被另一个进程更改的变量的引用,或者 (2) x 未被写入由另一个进程和 e 不包含对由其他进程更改的变量的引用。
int x = 0, y = 0;
co x = x+1; // y= y=1; oc;
满足属性因为x没有被第二个进程读取并且没有临界区
int x = 1, y = 1;
co <x = x + y;>
// y = 0;
// x = x - y;
oc
虽然我不明白这个程序如何满足 属性。第一条语句是原子语句,所以它无论如何都无效,但是 y=0 会影响第三条语句 x 结果,所以我不明白这是如何满足 属性?
我想知道这可能意味着什么......那是一个特别潮湿的下午,我去看看发现:
At-Most-Once Property
Andrews defined a condition called at-most-once under which expression evaluations and assignments will appear to be atomic.
A critical reference in an expression is a reference to a variable that is changed by another thread.
An assignment statement
x = e
satisfies the at-most-once property if either:1.1:
e
contains at most one critical reference andx
is neither read nor written by another thread, or1.2:
e
contains no critical references, in which casex
may be read or written by other threads.An expression that is not in an assignment satisfies at-most-once property if it contains no more than one critical reference.
This condition is called at-most-once because there can be at most one shared variable, and the shared variable can be referenced at most one time. ...
我认为你的谜题的关键是这句话:
... Assignment statements that satisfy at-most-once property appear to execute atomically even though they are not atomic.
和
... That is, we would get the same results from executing these assignment statements even if we were to somehow prevent the interleaving of their machine instructions so that the assignment statements were forced to execute atomically.
假设我理解正确:
<x = x + y;>
是原子读-修改-写。所以这已经是原子的——它不需要 "appear to execute atomically".y = 0
是 最多一次 所以满足上面的 (1.2) 并且会 "appear to execute atomically"。因为它确实......这意味着
x = x - y
也是 最多一次
……我觉得。 (当您找到明确的答案时,请告诉我们。)
很好奇这个有什么用!