我正在尝试重现Dijkstra在题为“协作顺序进程”的文章中编写的ALGOL 60代码,代码是第一次尝试解决互斥问题,这里是语法:
begin integer turn; turn:= 1;
parbegin
process 1: begin Ll: if turn = 2 then goto Ll;
critical section 1;
turn:= 2;
remainder of cycle 1; goto L1
end;
process 2: begin L2: if turn = 1 then goto L2;
critical section 2;
turn:= 1;
remainder of cycle 2; goto L2
end
parend
end
所以我尝试在Promela中重现上面的代码,这是我的代码:
#define true 1
#define Aturn true
#define Bturn false
bool turn, status;
active proctype A()
{
L1: (turn == 1);
status = Aturn;
goto L1;
/* critical section */
turn = 1;
}
active proctype B()
{
L2: (turn == 2);
status = Bturn;
goto L2;
/* critical section */
turn = 2;
}
never{ /* ![]p */
if
:: (!status) -> skip
fi;
}
init
{ turn = 1;
run A(); run B();
}
我要做的是,验证公平属性永远不会成立,因为标签L1无限运行。
这里的问题是我永远不会声称阻止不产生任何错误,我得到的输出只是说我的陈述从未到达..
这是iSpin的实际输出
spin -a dekker.pml
gcc -DMEMLIM=1024 -O2 -DXUSAFE -DSAFETY -DNOCLAIM -w -o pan pan.c
./pan -m10000
Pid: 46025
(Spin Version 6.2.3 -- 24 October 2012)
+ Partial Order Reduction
Full statespace search for:
never claim - (not selected)
assertion violations +
cycle checks - (disabled by -DSAFETY)
invalid end states +
State-vector 44 byte, depth reached 8, errors: 0
11 states, stored
9 states, matched
20 transitions (= stored+matched)
0 atomic steps
hash conflicts: 0 (resolved)
Stats on memory usage (in Megabytes):
0.001 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
unreached in proctype A
dekker.pml:13, state 4, "turn = 1"
dekker.pml:15, state 5, "-end-"
(2 of 5 states)
unreached in proctype B
dekker.pml:20, state 2, "status = 0"
dekker.pml:23, state 4, "turn = 2"
dekker.pml:24, state 5, "-end-"
(3 of 5 states)
unreached in claim never_0
dekker.pml:30, state 5, "-end-"
(1 of 5 states)
unreached in init
(0 of 4 states)
pan: elapsed time 0 seconds
No errors found -- did you verify all claims?
我已在never{..}
块上阅读了旋转的所有文档,但找不到我的答案(这里是link),我也尝试使用ltl{..}
块同样(link)但这只是给了我语法错误,即使它在文档中明确提到它可以在init
和proctypes
之外,有人可以帮我纠正这段代码请?
谢谢
答案 0 :(得分:1)
你已经重新定义了'真',这可能不太好。我认为重新定义和从未声称失败。但是,失败对你的目标来说并不重要 - '状态'的初始状态是“错误的”,因此永远不会声称退出,这是失败。
此外,将1或0分配给bool是一种稍微不好的形式;指定true或false - 或使用bit。为什么不更密切地遵循Dijkstra代码 - 使用'int'或'byte'。在这个问题上,性能不会成为一个问题。
如果您要打电话'跑',则不需要'有效' - 只需要一个或那个。
我对'过程1'的翻译将是:
proctype A ()
{
L1: turn !=2 ->
/* critical section */
status = Aturn;
turn = 2
/* remainder of cycle 1 */
goto L1;
}
但我可能错了。