考虑这个片段:
chan sel = [0] of {int};
active proctype Selector(){
int not_me;
endselector:
do
:: sel ? not_me;
if
:: 0 != not_me -> sel ! 0;
:: 1 != not_me -> sel ! 1;
:: 2 != not_me -> sel ! 2;
:: 3 != not_me -> sel ! 3;
:: else -> -1;
fi
od
}
proctype H(){
int i = -1;
int count = 1000;
do
:: sel ! i; sel ? i; printf("currently selected: %d\n",i); count = count -1;
:: count < 0 -> break;
od
assert(false);
}
init{
atomic{
run H();
}
}
您希望这可以任意打印漂亮的值 0..3,直到计数器低于 0,此时它可以打印另一个数字,也可以终止。
然而,情况似乎并非如此。
返回的唯一值是 0,然后是 1,然后是 0,然后是 1,然后是 0,然后是 1,...
我是否以某种方式误解了 if/fi 语句的“非确定性”?
(如果重要的话,在 ubuntu 上使用 ispin)。