promela - Promela: Why is not this atomic block equivalent to an assignment statement?
问题描述
I wrote following Promela code. This code simulates the situation where two processes increment a shared counter.
I expected the assert
in the code must be true, but SPIN says "assertion violated". Strangely, when I replaced the atomic
block with count = count + 1
, the error has been gone.
Why is not this atomic block equivalent to an assignment statement?
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);
}
Execution result:
$ 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
解决方案
This is a known bug, it has been fixed (at least) since version 6.4.8
of Spin.
Keep the tool updated.
Note: added answer as requested by @Brishna Batool.
推荐阅读
- angular - Angular Crossfade 动画在最后一步跳跃
- bash - sed 用管道和星号替换字符串
- angular - 如何使用httpClient以角度下载大文件(> 1GB)?
- scheme - 过滤带有索引的列表 MIT-scheme
- javascript - 使用 Nuxt Js i18n 在头部添加 RTL 条件
- visual-c++ - Visual Studio MFC 在键入/动态时更改编辑控件中的文本
- shared-libraries - liboctinterp.so.3 - 无法打开共享对象文件
- python - 异常处理:评估多个语句
- react-native - 应用程序关闭时如何删除异步存储
- python - 带有 Amazon Linux 2 AMI 的 32 GB EC2 为 9.6 GB Pandas 数据帧引发内存错误