- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我编写了以下 Peterson 算法模型:
bool want[2], turn
ltl { []<>P[0]@cs }
active [2] proctype P() {
pid me = _pid
pid you = 1 - me
do
:: want[me] = true
turn = you
!want[you] || turn == me
cs: want[me] = false
od
}
据我了解,该算法提供了免于饥饿的自由,正如线性时序逻辑声明中所表达的那样。那为什么我分析模型的时候会报错呢?
ltl ltl_0: [] (<> ((P[0]@cs)))
pan:1: acceptance cycle (at depth 2)
pan: wrote peterson.pml.trail
(Spin Version 6.4.8 -- 2 March 2018)
Warning: Search not completed
+ Partial Order Reduction
Full statespace search for:
never claim + (ltl_0)
assertion violations + (if within scope of claim)
acceptance cycles + (fairness disabled)
invalid end states - (disabled by never claim)
State-vector 36 byte, depth reached 9, errors: 1
5 states, stored
0 states, matched
5 transitions (= stored+matched)
0 atomic steps
hash conflicts: 0 (resolved)
Stats on memory usage (in Megabytes):
0.000 equivalent memory usage for states (stored*(State-vector + overhead))
0.291 actual memory usage for states
128.000 memory used for hash table (-w24)
0.534 memory used for DFS stack (-m10000)
128.730 total actual memory usage
pan: elapsed time 0 seconds
最佳答案
你是对的,Peterson 算法应该不会出现饥饿问题,而且确实如此。
饥饿发生在进程请求一些资源但永久拒绝时。因此,进度公式的更好编码将是:
ltl p1 { [] (P[0]@req -> <> (P[0]@cs) }
哪里req
是一个标签,放置如下:
do
:: true ->
req: want[me] = true
turn = you
!want[you] || turn == me
cs: want[me] = false
od
<小时/>
不幸的是,发现之前的公式仍然是false
.
其原因是,您正在检查模型的系统的进程调度程序一般来说并不公平。事实上,它允许执行 _pid
的进程。等于 0
永远不会被选择执行。
spin
model-checker 为您提供了一个正好适合这种情况的反例:
~$ spin -t -g -l -p t.pml
ltl ltl_0: [] (<> ((P[0]@cs)))
starting claim 1
using statement merging
Never claim moves to line 3 [(!((P[0]._p==cs)))]
2: proc 1 (P:1) t.pml:10 (state 1) [want[me] = 1]
want[0] = 0
want[1] = 1
<<<<<START OF CYCLE>>>>>
Never claim moves to line 8 [(!((P[0]._p==cs)))]
4: proc 1 (P:1) t.pml:11 (state 2) [turn = you]
6: proc 1 (P:1) t.pml:12 (state 3) [((!(want[you])||(turn==me)))]
8: proc 1 (P:1) t.pml:13 (state 4) [want[me] = 0]
want[0] = 0
want[1] = 0
10: proc 1 (P:1) t.pml:10 (state 1) [want[me] = 1]
want[0] = 0
want[1] = 1
spin: trail ends after 10 steps
#processes: 2
want[0] = 0
want[1] = 1
turn = 0
cs = 0
10: proc 1 (P:1) t.pml:11 (state 2)
10: proc 0 (P:1) t.pml:9 (state 5)
10: proc - (ltl_0:1) _spin_nvr.tmp:7 (state 10)
2 processes created
<小时/>
解决方法。
此问题基本上有两种解决方法:
第一个只是询问,如果某个进程尝试进入临界区,那么某个进程最终会进入它:
ltl p2 { [] ((P[0]@req || P[1]@req) -> <> (P[0]@cs || P[1]@cs) }
这确保了整个系统的进展,但并不能保证 P[0]
中的任何一个。和P[1]
具体来说不会导致饥饿。
第二个是引入一个公平条件,该条件要求将模型检查仅集中在那些进程被安排无限频繁执行的执行上:
ltl p3 { ([]<> (_last == 0)) -> [] (P[0]@req -> <> (P[0]@cs)) }
哪里_last
是预定义的内部变量,如 docs 中所述。如下:
DESCRIPTION
_last
is a predefined, global, read-only variable of type pid that holds the instantiation number of the process that performed the last step in the current execution sequence. The initial value of_last
is zero.The
_last
variable can only be used inside never claims. It is an error to assign a value to this variable in any context.
不幸的是,在检查模型是否存在饥饿时,这种方法并不是那么好。这是因为需要 [] <> _last == 0
不仅会删除 P[0]
中的任何执行由于调度程序的不公平性,并没有无限频繁地调度执行,但也包括 P[0]
的情况。由于实际的饥饿问题而没有安排。
适当的解决方案。
我建议更改您的模型,以便 P[0]
执行忙等待,而不是在等待自己的回合时阻塞。这使得使用_last
当试图证明不存在饥饿时问题较少。最终模型将是:
bool flag[2], turn
active [2] proctype P() {
pid i = _pid;
pid j = 1 - i;
do
:: true ->
req: flag[i] = true
turn = j;
do
:: (flag[j] && (turn == j)) -> skip
:: else -> break;
od;
cs: skip;
flag[i] = false;
od
}
ltl p1 { (
([]<> (_last == 0)) &&
([]<> (_last == 1))
) ->
([] (P[0]@req -> <> (P[0]@cs)))
}
并且该属性确实经过验证,而没有丢弃任何可能有趣的执行跟踪:
~$ spin -a t.pml
ltl p1: (! (([] (<> ((_last==0)))) && ([] (<> ((_last==1)))))) || ([] ((! ((P[0]@req))) || (<> ((P[0]@cs)))))
~$ gcc pan.c
~$ ./a.out -a
(Spin Version 6.4.8 -- 2 March 2018)
Full statespace search for:
never claim + (p1)
assertion violations + (if within scope of claim)
acceptance cycles + (fairness disabled)
invalid end states - (disabled by never claim)
State-vector 40 byte, depth reached 97, errors: 0
269 states, stored (415 visited)
670 states, matched
1085 transitions (= visited+matched)
0 atomic steps
hash conflicts: 0 (resolved)
Stats on memory usage (in Megabytes):
0.017 equivalent memory usage for states (stored*(State-vector + overhead))
0.287 actual memory usage for states
128.000 memory used for hash table (-w24)
0.534 memory used for DFS stack (-m10000)
128.730 total actual memory usage
unreached in proctype P
t.pml:18, state 16, "-end-"
(1 of 16 states)
unreached in claim p1
_spin_nvr.tmp:23, state 33, "-end-"
(1 of 33 states)
pan: elapsed time 0 seconds
请注意,我们需要 P[0]
和P[1]
允许无限频繁地执行,否则会发现另一个虚假的反例。
Is this model of Peterson's algorithm incorrect?
因此,为了更直接地回答您的问题,您的模型在功能上并不是不正确,但为了适本地验证不存在饥饿,有必要执行一些小的更改。
关于model-checking - Peterson 算法的这个模型是错误的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52694550/
这个问题在这里已经有了答案: What's the proper value for a checked attribute of an HTML checkbox? (10 个答案) 关闭 8 年
我使用这个制作了自定义复选框: enter link description here 也可在 stackoverflow 上获得:enter link description here 但我正在尝试
我需要使用 CSS“checkbox-hack”来实现滑动菜单指示器效果,我唯一的方法是通过 JavaScript 附加输入元素。我被迫通过在线工具 MonoSolutions 执行此操作,并且我受到
此代码运行良好,但缺少一些我需要的东西。基本上,如果输入有一个 checked="checked" 属性,它应该使其他两个元素保持禁用状态。如果未选中,则元素已启用。 这是我在 jsFiddle 上的
当我的人 checkout 文件时,我希望他们将其锁定,以便其他人也无法进行更改,我从这篇文章中看到:http://msdn.microsoft.com/en-us/library/jj155783.
请告诉我这些函数的作用。 最佳答案 这些是基于框架的、与语言无关的方法,用于在 .NET 中定义代码契约。虽然某些语言(如 spec# 和 Delphi Prism)对代码契约具有一流的语言支持,但这
假设以下场景:您有 2 个单选按钮,它们具有相同的名称,并且都被选中(我知道这是无效的): 为什么下面两个选择器的行为不同? $('.input:checked').size(); // retu
我正在尝试收听广播。以下均不起作用: [编辑] $('selector').attr('checked','checked'); $('selector').attr('checked',true);
我实际上在努力理解此类型错误。 任何人都知道我如何更正代码?谢谢 CheckIn checkin1 = new CheckIn(location1, dt); CheckInMonths checkI
我有这段代码,但不起作用。 .on("click","span.name", function selectThisName(e) { if (e.altKey) {
我现在是 Espresso 的新手,我遇到了这个异常: android.support.test.espresso.AmbiguousViewMatcherException: 'with id: a
我已经创建了一个基本的 2 单选按钮表单,如下面的示例所示。 观察浏览器渲染,我们看到元素 1 被选中。我们检查元素 1 和元素 2。 当我点击元素 2 时,我希望元素 1 的 checked=che
我在查找以下 jquery/checkbox 行为的原因时遇到问题。 $( this.obj + ' table.sgrid-content > thead > tr > th > input.sel
以下逻辑应用在上午 10 点触发并运行 SQL Server 查询。从图片中可以看出,结果集是空的。 条件检查检查查询的结果集是否为空。 (第二张图) 这仍然如何转化为 True?结果显然是空的。 最
我想知道哪种操作更快: int c = version1.compareTo(version2); 这个 if (c == 1) 或者这个 if (c > 0) 符号比较是否只使用一位检查,而相等比较
我有一个包含大约 100 个问题的表单,每个问题都有一个单选按钮和一些复选框,因此我需要用户能够保存表单并在以后加载它。我还需要检查用户在此 session 中更改了哪些。 本题解决问题:How ca
我正在编写一个小程序,需要用户决定一些 bool 值。我已经制作了复选框来处理这一部分,但问题是每次我选中或取消选中一个复选框时,所有其他复选框都会跟随。 我在网上搜索过,但我找到的唯一解释( pyt
我有以下代码片段(我使用的是 jQuery 1.4.2): $.post('/Ads/GetAdStatsRow/', { 'ad_id': id }, function(result) {
我的代码发生了一些奇怪的事情。我有两个按钮,其中一个带有 .add 和 .remove 类,有一个复选框会根据按下哪个按钮而打开和关闭,因此如果您使用删除按钮删除,则选中的复选框将被选中,否则复选框将
我陷入了一种情况,我必须通过“选中”工具栏中的复选框来“选中”列表中存在的所有复选框。 这是创建复选框列表的代码:- itemTpl: 'checked="checked" /> {groupName
我是一名优秀的程序员,十分优秀!