我试图弄清楚 SPIN 如何在以下示例中选择执行和终止进程的顺序。我意识到 SPIN 的主要焦点是分析并发进程,但出于我的目的,我只对简单的线性执行感兴趣。在下面的示例中,我只希望 step1() 然后 step2() 以该顺序执行。
int globA;
int globB;
proctype step1() {
atomic {
globA = 1;
}
}
proctype step2() {
atomic {
globB = 2;
}
}
init {
atomic {
run step1();
run step2();
}
}
但是,即使使用原子 {} 声明,进程在执行时也会交错。使用命令spin -p my_pml_code.pml
我只得到以下 3 个输出(我运行了很多次,这些是唯一的输出)。
运行 1:
0: proc - (:root:) creates proc 0 (:init:)
Starting step1 with pid 1
1: proc 0 (:init::1) creates proc 1 (step1)
1: proc 0 (:init::1) pml_testing/transition_testing.pml:16 (state 1) [(run step1())]
Starting step2 with pid 2
2: proc 0 (:init::1) creates proc 2 (step2)
2: proc 0 (:init::1) pml_testing/transition_testing.pml:17 (state 2) [(run step2())]
3: proc 2 (step2:1) pml_testing/transition_testing.pml:11 (state 1) [globB = 2]
4: proc 1 (step1:1) pml_testing/transition_testing.pml:6 (state 1) [globA = 1]
4: proc 2 (step2:1) terminates
4: proc 1 (step1:1) terminates
4: proc 0 (:init::1) terminates
3 processes created
顺序是 proc 0 -> 0 -> 0 -> 0 ->2 -> 1 -> 2 -> 1 -> 0
运行 2:
0: proc - (:root:) creates proc 0 (:init:)
Starting step1 with pid 1
1: proc 0 (:init::1) creates proc 1 (step1)
1: proc 0 (:init::1) pml_testing/transition_testing.pml:16 (state 1) [(run step1())]
Starting step2 with pid 2
2: proc 0 (:init::1) creates proc 2 (step2)
2: proc 0 (:init::1) pml_testing/transition_testing.pml:17 (state 2) [(run step2())]
3: proc 1 (step1:1) pml_testing/transition_testing.pml:6 (state 1) [globA = 1]
4: proc 2 (step2:1) pml_testing/transition_testing.pml:11 (state 1) [globB = 2]
4: proc 2 (step2:1) terminates
4: proc 1 (step1:1) terminates
4: proc 0 (:init::1) terminates
3 processes created
顺序是 proc 0 -> 0 -> 0 -> 0 -> 1 -> 2 -> 2 -> 1 -> 0
运行 3:
0: proc - (:root:) creates proc 0 (:init:)
Starting step1 with pid 1
1: proc 0 (:init::1) creates proc 1 (step1)
1: proc 0 (:init::1) pml_testing/transition_testing.pml:16 (state 1) [(run step1())]
Starting step2 with pid 2
2: proc 0 (:init::1) creates proc 2 (step2)
2: proc 0 (:init::1) pml_testing/transition_testing.pml:17 (state 2) [(run step2())]
3: proc 2 (step2:1) pml_testing/transition_testing.pml:11 (state 1) [globB = 2]
3: proc 2 (step2:1) terminates
4: proc 1 (step1:1) pml_testing/transition_testing.pml:6 (state 1) [globA = 1]
4: proc 1 (step1:1) terminates
4: proc 0 (:init::1) terminates
3 processes created
顺序是 proc 0 -> 0 -> 0 -> 0 ->2 -> 2 -> 1 -> 1 -> 0
我试图简单地得到它的输出: proc 0 -> 0 -> 0 -> 0 ->1 -> 1 -> 2 -> 2 -> 0
我意识到 proc 0 在 1 和 2 终止之前无法终止,但是为什么 2 和 1 的终止是不确定的交错的?当 init 函数是原子的并且因此应该按顺序执行时,为什么 SPIN 在执行 proc 1 和 proc 2 之间随机选择?为什么我可以让 proc 2 在 proc 1 之前启动和终止(在 Run 3 中),而不是相反?
注意:我也使用dstep
代替测试了这个atomic
,我得到了相同的结果。