Promela:将数组传递给新的proctype

时间:2017-10-12 11:12:11

标签: arrays promela spin

我需要将一个数组从父进程传递到 Promela 中的子进程,但它不允许我这样做。另外,我在使这个数组全局化方面有一些限制,所以也不能这样做。怎么办呢?

例如:

proctype B(int hg)
{
 ..
}

proctype A()
{
    int hg[n];
    run B(hg);
}

1 个答案:

答案 0 :(得分:1)

run的文档说:

  

说明运行运算符将a的名称作为参数   先前声明的proctype,以及可能为空的实际列表   必须与正式的数量和类型相匹配的参数   该proctype的参数。 [...]

     

run运算符必须将实际参数值传递给新进程,   如果proctype声明指定了非空的形式参数   名单。 只有消息通道和基本数据类型的实例才可以   作为参数传递。 无法传递变量数组。

     

[强调是我的]

您应该考虑使用全局变量。

在下面的示例中,我们将数组括在user-defined structured data type 中 - 以及进程可能需要的任何其他参数 - ,并声明全局此类记录的向量。然后,我们不是直接传递array参数,而是交换包含其他过程参数的记录index

#define m 10
#define n 10

typedef Record {
    int hg[n];
    // ...
    // other parameters
    // ... 
};

Record data[m];

active proctype A ()
{
    int idx = 1;

    data[idx].hg[0] = 12;

    // ...

    run B(idx);
}

proctype B (int idx)
{
    assert(data[idx].hg[0] == 12);

    data[idx].hg[0] = 17;

    // ...
}

这将允许您生成验证者:

~$ spin -search -bfs test.pml
...
State-vector 424 byte, depth reached 6, errors: 0
...

或者只有在您不需要生成验证程序时,您才可以简单地传递记录实例。的 e.g。

#define n 10

typedef Record {
    int hg[n];
    // ...
    // other parameters
    // ... 
};

active proctype A ()
{
    Record my_record;

    my_record.hg[0] = 12;

    // ...

    run B(my_record);
}

proctype B (Record data)
{
    assert(data.hg[0] == 12);

    data.hg[0] = 17;

    // ...
}

但是,此在模拟模式下工作,特别是允许您生成验证程序:

~$ spin -search -bfs test.pml
spin: test.pml:18, Error: hidden array in parameter data

事实上,typedef的文档明确提到了

  

typedef对象也可以用作run语句中的参数,但在这种情况下它可能不包含任何数组

     

[强调是我的]