Promela:为什么这个原子块不等同于赋值语句?

时间:2019-02-02 08:11:57

标签: promela spin

我写了以下Promela代码。此代码模拟了两个进程递增共用的对的情况。

我希望代码中的assert必须为真,但SPIN表示“违反了断言”。奇怪的是,当我将atomic块替换为count = count + 1时,错误消失了。

为什么不是该块等效原子到赋值语句?

byte count = 0;
bool finished[2];

proctype Increment(byte index) {
    atomic {
        byte c = count;
        c = c + 1;
        count = c;
    }
    finished[index] = true;
}

init {
    run Increment(0);
    run Increment(1);

    (finished[0] && finished[1]);
    assert(count == 2);
}

执行结果:

$ spin -a counter.pml
$ gcc -o pan pan.c
$ ./pan
pan:1: assertion violated (count==2) (at depth 9)
pan: wrote counter.pml.trail

(Spin Version 6.4.6 -- 2 December 2016)
Warning: Search not completed
        + Partial Order Reduction

Full statespace search for:
        never claim             - (none specified)
        assertion violations    +
        acceptance   cycles     - (not selected)
        invalid end states      +

State-vector 36 byte, depth reached 11, errors: 1
       28 states, stored
        3 states, matched
       31 transitions (= stored+matched)
        0 atomic steps
hash conflicts:         0 (resolved)

Stats on memory usage (in Megabytes):
    0.002       equivalent memory usage for states (stored*(State-vector + overhead))
    0.292       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

1 个答案:

答案 0 :(得分:1)

这是一个已知的错误,至少自Spin版本6.4.8起已得到修复。

保持工具更新。


注意: 根据@Brishna Batool的要求添加了答案。